SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 1
www.nand2tetris.org
Building a Modern Computer From First Principles
Virtual Machine
Part II: Program Control
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 2
Where we are at:
Assembler
Chapter 6
H.L. Language
&
Operating Sys.
abstract interface
Compiler
Chapters 10 - 11
VM Translator
Chapters 7 - 8
Computer
Architecture
Chapters 4 - 5
Gate Logic
Chapters 1 - 3 Electrical
Engineering
Physics
Virtual
Machine
abstract interface
Software
hierarchy
Assembly
Language
abstract interface
Hardware
hierarchy
Machine
Language
abstract interface
Hardware
Platform
abstract interface
Chips &
Logic Gates
abstract interface
Human
Thought
Abstract design
Chapters 9, 12
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 3
The big picture
. . .
RISC
machine
VM language
other digital platforms, each equipped
with its VM implementation
RISC
machine
language
Hack
computer
Hack
machine
language
CISC
machine
language
CISC
machine
. . .
written in
a high-level
language
Any
computer
. . .
VM
implementation
over CISC
platforms
VM imp.
over RISC
platforms
VM imp.
over the Hack
platform
VM
emulator
Some Other
language
Jack
language
Some
compiler Some Other
compiler
Jack
compiler
. . .Some
language
. . .
Chapters
1-6
Chapters
7-8
Chapters
9-13
A Java-based emulator
is included in the course
software suite
Implemented in
Projects 7-8
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 4
The VM langauge
Goal: Complete the specification and implementation of the VM model and language
Method: (a) specify the abstraction (model’s constructs and commands)
(b) propose how to implement it over the Hack platform.
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
previous
lecture
this
lecture
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 5
The compilation challenge
class Main {
static int x;
function void main() {
// Inputs and multiplies two numbers
var int a, b, c;
let a = Keyboard.readInt(“Enter a number”);
let b = Keyboard.readInt(“Enter a number”);
let c = Keyboard.readInt(“Enter a number”);
let x = solve(a,b,c);
return;
}
}
// Solves a quadearic equation (sort of)
function int solve(int a, int b, int c) {
var int x;
if (~(a = 0))
x=(-b+sqrt(b*b–4*a*c))/(2*a);
else
x=-c/b;
return x;
}
}
class Main {
static int x;
function void main() {
// Inputs and multiplies two numbers
var int a, b, c;
let a = Keyboard.readInt(“Enter a number”);
let b = Keyboard.readInt(“Enter a number”);
let c = Keyboard.readInt(“Enter a number”);
let x = solve(a,b,c);
return;
}
}
// Solves a quadearic equation (sort of)
function int solve(int a, int b, int c) {
var int x;
if (~(a = 0))
x=(-b+sqrt(b*b–4*a*c))/(2*a);
else
x=-c/b;
return x;
}
}
Source code (high-level language)
Our ultimate goal:
Translate high-level
programs into
executable code.
Compiler
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
...
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
...
Target code
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 6
The compilation challenge / two-tier setting
if (~(a = 0))
x = (-b+sqrt(b*b–4*a*c))/(2*a)
else
x = -c/b
if (~(a = 0))
x = (-b+sqrt(b*b–4*a*c))/(2*a)
else
x = -c/b
Jack source code
push a
push 0
eq
if-goto elseLabel
push b
neg
push b
push b
call mult
push 4
push a
call mult
push c
call mult
call sqrt
add
push 2
push a
call mult
div
pop x
goto contLable
elseLabel:
push c
neg
push b
call div
pop x
contLable:
push a
push 0
eq
if-goto elseLabel
push b
neg
push b
push b
call mult
push 4
push a
call mult
push c
call mult
call sqrt
add
push 2
push a
call mult
div
pop x
goto contLable
elseLabel:
push c
neg
push b
call div
pop x
contLable:
Compiler
VM (pseudo) code
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010010
1110001100000001
...
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010000
1110111111001000
0000000000010001
1110101010001000
0000000000010000
1111110000010000
0000000000000000
1111010011010000
0000000000010010
1110001100000001
0000000000010000
1111110000010000
0000000000010001
0000000000010010
1110001100000001
...
VM translator
Machine code
We’ll develop the compiler later
in the course
We now turn to describe how to
complete the implementation of
the VM language
That is -- how to translate each
VM command into assembly
commands that perform the
desired semantics.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 7
// Computes x = (-b + sqrt(b^2 -4*a*c)) / 2*a
if (~(a = 0))
x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a)
else
x = - c / b
// Computes x = (-b + sqrt(b^2 -4*a*c)) / 2*a
if (~(a = 0))
x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a)
else
x = - c / b
Typical compiler’s source code input:
The compilation challenge
arithmetic
expressions
function call and
return logic
boolean
expressions
program flow logic
(branching)
How to translate such high-level code into machine language?
In a two-tier compilation model, the overall translation challenge is broken between a
front-end compilation stage and a subsequent back-end translation stage
In our Hack-Jack platform, all the above sub-tasks (handling arithmetic / boolean
expressions and program flow / function calling commands) are done by the back-end, i.e. by
the VM translator.
(previous lecture)(previous lecture)(this lecture) (this lecture)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 8
Lecture plan
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
previous
lecture
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 9
Program flow commands in the VM language
How to translate these three abstractions into assembly?
Simple: label declarations and goto directives can be
effected directly by assembly commands
More to the point: given any one of these three VM
commands, the VM Translator must emit one or more
assembly commands that effects the same semantics
on the Hack platfrom
How to do it? see project 8.
label c // label declaration
goto c // unconditional jump to the
// VM command following the label c
if-goto c // pops the topmost stack element;
// if it’s not zero, jumps to the
// VM command following the label c
label c // label declaration
goto c // unconditional jump to the
// VM command following the label c
if-goto c // pops the topmost stack element;
// if it’s not zero, jumps to the
// VM command following the label c
In the VM language, the program flow abstraction is
delivered using three commands:
VM code example:
function mult 1
push constant 0
pop local 0
label loop
push argument 0
push constant 0
eq
if-goto end
push argument 0
push 1
sub
pop argument 0
push argument 1
push local 0
add
pop local 0
goto loop
label end
push local 0
return
function mult 1
push constant 0
pop local 0
label loop
push argument 0
push constant 0
eq
if-goto end
push argument 0
push 1
sub
pop argument 0
push argument 1
push local 0
add
pop local 0
goto loop
label end
push local 0
return
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 10
Lecture plan
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Arithmetic / Boolean commands
add
sub
neg
eq
gt
lt
and
or
not
Memory access commands
pop x (pop into x, which is a variable)
push y (y being a variable or a constant)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
Program flow commands
label (declaration)
goto (label)
if-goto (label)
Function calling commands
function (declaration)
call (a function)
return (from a function)
previous
lecture
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 11
Subroutines
Subroutines = a major programming artifact
Basic idea: the given language can be extended at will by user-defined
commands ( aka subroutines / functions / methods ...)
Important: the language’s primitive commands and the user-defined commands
have the same look-and-feel
This transparent extensibility is the most important abstraction delivered by
high-level programming languages
The challenge: implement this abstraction, i.e. allow the program control to flow
effortlessly between one subroutine to the other
“A well-designed system consists of a collection of black box modules,
each executing its effect like magic”
(Steven Pinker, How The Mind Works)
// Compute x = (-b + sqrt(b^2 -4*a*c)) / 2*a
if (~(a = 0))
x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a)
else
x = - c / b
// Compute x = (-b + sqrt(b^2 -4*a*c)) / 2*a
if (~(a = 0))
x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a)
else
x = - c / b
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 12
Subroutines in the VM language
The invocation of the VM’s primitive
commands and subroutines
follow exactly the same rules:
The caller pushes the necessary
argument(s) and calls the command /
function for its effect
The called command / function is
responsible for removing the argument(s)
from the stack, and for popping onto
the stack the result of its execution.
function mult 1
push constant 0
pop local 0 // result (local 0) = 0
label loop
push argument 0
push constant 0
eq
if-goto end // if arg0 == 0, jump to end
push argument 0
push 1
sub
pop argument 0 // arg0--
push argument 1
push local 0
add
pop local 0 // result += arg1
goto loop
label end
push local 0 // push result
return
function mult 1
push constant 0
pop local 0 // result (local 0) = 0
label loop
push argument 0
push constant 0
eq
if-goto end // if arg0 == 0, jump to end
push argument 0
push 1
sub
pop argument 0 // arg0--
push argument 1
push local 0
add
pop local 0 // result += arg1
goto loop
label end
push local 0 // push result
return
Called code, aka “callee” (example)
...
// computes (7 + 2) * 3 - 5
push constant 7
push constant 2
add
push constant 3
call mult
push constant 5
sub
...
...
// computes (7 + 2) * 3 - 5
push constant 7
push constant 2
add
push constant 3
call mult
push constant 5
sub
...
Calling code (example)
VM subroutine
call-and-return
commands
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 13
Function commands in the VM language
Q: Why this particular syntax?
A: Because it simplifies the VM implementation (later).
function g nVars // here starts a function called g,
// which has nVars local variables
call g nArgs // invoke function g for its effect;
// nArgs arguments have already been pushed onto the stack
return // terminate execution and return control to the caller
function g nVars // here starts a function called g,
// which has nVars local variables
call g nArgs // invoke function g for its effect;
// nArgs arguments have already been pushed onto the stack
return // terminate execution and return control to the caller
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 14
Function call-and-return conventions
function mult 1
push constant 0
pop local 0 // result (local 0) = 0
label loop
... // rest of code ommitted
label end
push local 0 // push result
return
function mult 1
push constant 0
pop local 0 // result (local 0) = 0
label loop
... // rest of code ommitted
label end
push local 0 // push result
return
called function aka “callee” (example)
function demo 3
...
push constant 7
push constant 2
add
push constant 3
call mult
...
function demo 3
...
push constant 7
push constant 2
add
push constant 3
call mult
...
Calling function
Call-and-return programming convention
The caller must push the necessary argument(s), call the callee, and wait for it to return
Before the callee terminates (returns), it must push a return value
At the point of return, the callee’s resources are recycled, the caller’s state is re-instated,
execution continues from the command just after the call
Caller’s net effect: the arguments were replaced by the return value
(just like with primitive commands)
Behind the scene
Recycling and re-instating subroutine resources and states is a major headache
Some agent (either the VM or the compiler) should manage it behind the scene “like magic”
In our implementation, the magic is VM / stack-based, and is considered a great CS gem.
Although not obvious in this
example, every VM function
has a private set of 5 memory
segments (local, argument,
this, that, pointer)
These resources exist as long
as the function is running.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 15
The function-call-and-return protocol
The caller’s view:
When I start executing, my argument segment has been initialized with actual
argument values passed by the caller
My local variables segment has been allocated and initialized to zero
The static segment that I see has been set to the static segment of the VM file to
which I belong, and the working stack that I see is empty
Before exiting, I must push a value onto the stack and then use the command return.
When I start executing, my argument segment has been initialized with actual
argument values passed by the caller
My local variables segment has been allocated and initialized to zero
The static segment that I see has been set to the static segment of the VM file to
which I belong, and the working stack that I see is empty
Before exiting, I must push a value onto the stack and then use the command return.
Before calling a function g, I must push onto the stack as many
arguments as needed by g
Next, I invoke the function using the command call g nArgs
After g returns:
The arguments that I pushed before the call have disappeared
from the stack, and a return value (that always exists)
appears at the top of the stack
All my memory segments (local, argument, this, that,
pointer) are the same as before the call.
Before calling a function g, I must push onto the stack as many
arguments as needed by g
Next, I invoke the function using the command call g nArgs
After g returns:
The arguments that I pushed before the call have disappeared
from the stack, and a return value (that always exists)
appears at the top of the stack
All my memory segments (local, argument, this, that,
pointer) are the same as before the call.
The callee’s (g ‘s) view:
Blue = VM function
writer’s responsibility
Black = black box magic,
delivered by the
VM implementation
Thus, the VM implementation
writer must worry about
the “black operations” only.
function g nVars
call g nArgs
return
function g nVars
call g nArgs
return
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 16
When function f calls function g, the VM implementation must:
Save the return address within f ‘s code:
the address of the command just after the call
Save the virtual segments of f
Allocate, and initialize to 0, as many local variables as needed by g
Set the local and argument segment pointers of g
Transfer control to g.
When g terminates and control should return to f, the VM implementation must:
Clear g ’s arguments and other junk from the stack
Restore the virtual segments of f
Transfer control back to f
(jump to the saved return address).
Q: How should we make all this work “like magic”?
A: We’ll use the stack cleverly.
The function-call-and-return protocol: the VM implementation view
function g nVars
call g nArgs
return
function g nVars
call g nArgs
return
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 17
The implementation of the VM’s stack on the host Hack RAM
Global stack:
the entire RAM area dedicated
to hold the stack
Working stack:
from SP onwards: the stack
that the current function sees
At any point of time, only one
function (the current function)
is executing; other functions
may be waiting up the calling
chain
Shaded areas: irrelevant to
the current function
The current function sees
only the working stack, as
well as its virtual memory
segments
The rest of the stack holds
the frozen states of all the
functions up the calling
hierarchy.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 18
Implementing the call g nArgs command
Implementation: If the VM is implemented as a program
that translates VM code into assembly code, the
translator must emit the above logic in assembly.
// In the course of implementing the code of f
// (the caller), we arrive to the command call g nArgs.
// we assume that nArgs arguments have been pushed
// onto the stack. What do we do next?
// We generate a symbol, let’s call it returnAddress;
// Next, we effect the following logic:
push returnAddress // saves the return address
push LCL // saves the LCL of f
push ARG // saves the ARG of f
push THIS // saves the THIS of f
push THAT // saves the THAT of f
ARG = SP-nArgs-5 // repositions SP for g
LCL = SP // repositions LCL for g
goto g // transfers control to g
returnAddress: // the generated symbol
// In the course of implementing the code of f
// (the caller), we arrive to the command call g nArgs.
// we assume that nArgs arguments have been pushed
// onto the stack. What do we do next?
// We generate a symbol, let’s call it returnAddress;
// Next, we effect the following logic:
push returnAddress // saves the return address
push LCL // saves the LCL of f
push ARG // saves the ARG of f
push THIS // saves the THIS of f
push THAT // saves the THAT of f
ARG = SP-nArgs-5 // repositions SP for g
LCL = SP // repositions LCL for g
goto g // transfers control to g
returnAddress: // the generated symbol
call g nArgscall g nArgs
None of this code is executed yet ...
At this point we are just generating
code (or simulating the VM code on
some platform)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 19
Implementing the function g nVars command
Implementation: If the VM is implemented as a program
that translates VM code into assembly code, the
translator must emit the above logic in assembly.
function g nVarsfunction g nVars
// to implement the command function g nVars,
// we effect the following logic:
g:
repeat nVars times:
push 0
// to implement the command function g nVars,
// we effect the following logic:
g:
repeat nVars times:
push 0
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 20
Implementing the return command
Implementation: If the VM is implemented as a program
that translates VM code into assembly code, the
translator must emit the above logic in assembly.
// In the course of implementing the code of g,
// we arrive to the command return.
// We assume that a return value has been pushed
// onto the stack.
// We effect the following logic:
frame = LCL // frame is a temp. variable
retAddr = *(frame-5) // retAddr is a temp. variable
*ARG = pop // repositions the return value
// for the caller
SP=ARG+1 // restores the caller’s SP
THAT = *(frame-1) // restores the caller’s THAT
THIS = *(frame-2) // restores the caller’s THIS
ARG = *(frame-3) // restores the caller’s ARG
LCL = *(frame-4) // restores the caller’s LCL
goto retAddr // goto returnAddress
// In the course of implementing the code of g,
// we arrive to the command return.
// We assume that a return value has been pushed
// onto the stack.
// We effect the following logic:
frame = LCL // frame is a temp. variable
retAddr = *(frame-5) // retAddr is a temp. variable
*ARG = pop // repositions the return value
// for the caller
SP=ARG+1 // restores the caller’s SP
THAT = *(frame-1) // restores the caller’s THAT
THIS = *(frame-2) // restores the caller’s THIS
ARG = *(frame-3) // restores the caller’s ARG
LCL = *(frame-4) // restores the caller’s LCL
goto retAddr // goto returnAddress
returnreturn
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 21
Bootstrapping
SP = 256 // initialize the stack pointer to 0x0100
call Sys.init // call the function that calls Main.main
SP = 256 // initialize the stack pointer to 0x0100
call Sys.init // call the function that calls Main.main
A high-level jack program (aka application) is a set of class files.
By a Jack convention, one class must be called Main, and this class must have at
least one function, called main.
The contract: when we tell the computer to execute a Jack program,
the function Main.main starts running
Implementation:
After the program is compiled, each class file is translated into a .vm file
The operating system is also implemented as a set of .vm files (aka “libraries”)
that co-exist alongside the program’s .vm files
One of the OS libraries, called Sys.vm, includes a method called init.
The Sys.init function starts with some OS initialization code (we’ll deal with this
later, when we discuss the OS), then it does call Main.main
Thus, to bootstrap, the VM implementation has to effect (e.g. in assembly),
the following operations:
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 22
Extends the VM implementation described in the last lecture (chapter 7)
The result: a single assembly program file with lots of agreed-upon symbols:
VM implementation over the Hack platform
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 23
Proposed API
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 24
Perspective
Benefits of the VM approach
Code transportability: compiling for
different platforms requires replacing only
the VM implementation
Language inter-operability: code of multiple
languages can be shared using the same VM
Common software libraries
Code mobility: Internet
Some virtues of the modularity implied by
the VM approach to program translation:
Improvements in the VM
implementation are shared by all
compilers above it
Every new digital device with a VM
implementation gains immediate access
to an existing software base
New programming languages can be
implemented easily using simple
compilers
. . .
VM language
RISC
machine
language
Hack
CISC
machine
language
. . .
written in
a high-level
language
. . .
VM
implementation
over CISC
platforms
VM imp.
over RISC
platforms
TranslatorVM
emulator
Some Other
language Jack
Some
compiler Some Other
compiler
compiler
. . .Some
language
. . .
Benefits of managed code:
Security
Array bounds, index checking, …
Add-on code
Etc.
VM Cons
Performance.

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Lecture 12 os
Lecture 12 osLecture 12 os
Lecture 12 os
 
Lecture 10 compiler i
Lecture 10 compiler iLecture 10 compiler i
Lecture 10 compiler i
 
Sequential logic
Sequential logicSequential logic
Sequential logic
 
Boolean arithmetic
Boolean arithmeticBoolean arithmetic
Boolean arithmetic
 
Introduction
IntroductionIntroduction
Introduction
 
nand2tetris 舊版投影片 -- 第二章 布林算術
nand2tetris 舊版投影片 -- 第二章 布林算術nand2tetris 舊版投影片 -- 第二章 布林算術
nand2tetris 舊版投影片 -- 第二章 布林算術
 
nand2tetris 舊版投影片 -- 第一章 布林邏輯
nand2tetris 舊版投影片 -- 第一章 布林邏輯nand2tetris 舊版投影片 -- 第一章 布林邏輯
nand2tetris 舊版投影片 -- 第一章 布林邏輯
 
Machine language
Machine languageMachine language
Machine language
 
Mutual Exclusion
Mutual ExclusionMutual Exclusion
Mutual Exclusion
 
Matlab workshop
Matlab workshopMatlab workshop
Matlab workshop
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Serial comm matlab
Serial comm matlabSerial comm matlab
Serial comm matlab
 
Advance Computer Architecture
Advance Computer ArchitectureAdvance Computer Architecture
Advance Computer Architecture
 
FLASHBRAIN report
FLASHBRAIN reportFLASHBRAIN report
FLASHBRAIN report
 
Matlab Serial Port
Matlab Serial PortMatlab Serial Port
Matlab Serial Port
 
Unit 2 module-2
Unit 2 module-2Unit 2 module-2
Unit 2 module-2
 
Sequential and combinational alu
Sequential and combinational alu Sequential and combinational alu
Sequential and combinational alu
 
Assembler1
Assembler1Assembler1
Assembler1
 
Más sobre el Algoritmo de Peterson
Más sobre el Algoritmo de PetersonMás sobre el Algoritmo de Peterson
Más sobre el Algoritmo de Peterson
 
Implementation of a stream cipher based on bernoulli's map
Implementation of a stream cipher based on bernoulli's mapImplementation of a stream cipher based on bernoulli's map
Implementation of a stream cipher based on bernoulli's map
 

Ähnlich wie Lecture 08 virtual machine ii

Implementation
ImplementationImplementation
Implementationhcicourse
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Vivek Singh
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackironSource
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
MSMDC_CLI363
MSMDC_CLI363MSMDC_CLI363
MSMDC_CLI363mokacao
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Java programming concept
Java programming conceptJava programming concept
Java programming conceptSanjay Gunjal
 
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...Design World
 
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)Samuel Collie
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEWshyamuopten
 
150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrindRaghu Palakodety
 
Shape12 6
Shape12 6Shape12 6
Shape12 6pslulli
 

Ähnlich wie Lecture 08 virtual machine ii (20)

Implementation
ImplementationImplementation
Implementation
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
GNURAdioDoc-8
GNURAdioDoc-8GNURAdioDoc-8
GNURAdioDoc-8
 
GNURAdioDoc-8
GNURAdioDoc-8GNURAdioDoc-8
GNURAdioDoc-8
 
MSMDC_CLI363
MSMDC_CLI363MSMDC_CLI363
MSMDC_CLI363
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
Hems
HemsHems
Hems
 
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...
“eXtending” the Automation Toolbox: Introduction to TwinCAT 3 Software and eX...
 
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)
Instrumentation of Unsafe C Methods to Safe Methods (Samuel Bret Collie) (1)
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind150104 3 methods for-binary_analysis_and_valgrind
150104 3 methods for-binary_analysis_and_valgrind
 
Shape12 6
Shape12 6Shape12 6
Shape12 6
 

Mehr von 鍾誠 陳鍾誠

用十分鐘瞭解 新竹科學園區的發展史
用十分鐘瞭解  新竹科學園區的發展史用十分鐘瞭解  新竹科學園區的發展史
用十分鐘瞭解 新竹科學園區的發展史鍾誠 陳鍾誠
 
用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus鍾誠 陳鍾誠
 
交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥鍾誠 陳鍾誠
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++鍾誠 陳鍾誠
 
西洋史 (你或許不知道但卻影響現代教育的那些事)
西洋史  (你或許不知道但卻影響現代教育的那些事)西洋史  (你或許不知道但卻影響現代教育的那些事)
西洋史 (你或許不知道但卻影響現代教育的那些事)鍾誠 陳鍾誠
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列鍾誠 陳鍾誠
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列鍾誠 陳鍾誠
 
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列鍾誠 陳鍾誠
 
用十分鐘理解 《微分方程》
用十分鐘理解  《微分方程》用十分鐘理解  《微分方程》
用十分鐘理解 《微分方程》鍾誠 陳鍾誠
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作鍾誠 陳鍾誠
 
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統鍾誠 陳鍾誠
 
系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統鍾誠 陳鍾誠
 
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器鍾誠 陳鍾誠
 
系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器鍾誠 陳鍾誠
 
系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言鍾誠 陳鍾誠
 
系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器鍾誠 陳鍾誠
 
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入鍾誠 陳鍾誠
 
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器鍾誠 陳鍾誠
 

Mehr von 鍾誠 陳鍾誠 (20)

用十分鐘瞭解 新竹科學園區的發展史
用十分鐘瞭解  新竹科學園區的發展史用十分鐘瞭解  新竹科學園區的發展史
用十分鐘瞭解 新竹科學園區的發展史
 
用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus用十分鐘搞懂 λ-Calculus
用十分鐘搞懂 λ-Calculus
 
交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥交⼤資訊⼯程學系備審資料 ⾱詠祥
交⼤資訊⼯程學系備審資料 ⾱詠祥
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++
 
西洋史 (你或許不知道但卻影響現代教育的那些事)
西洋史  (你或許不知道但卻影響現代教育的那些事)西洋史  (你或許不知道但卻影響現代教育的那些事)
西洋史 (你或許不知道但卻影響現代教育的那些事)
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
 
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列區塊鏈  (比特幣背後的關鍵技術)   -- 十分鐘系列
區塊鏈 (比特幣背後的關鍵技術) -- 十分鐘系列
 
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列梯度下降法  (隱藏在深度學習背後的演算法) -- 十分鐘系列
梯度下降法 (隱藏在深度學習背後的演算法) -- 十分鐘系列
 
用十分鐘理解 《微分方程》
用十分鐘理解  《微分方程》用十分鐘理解  《微分方程》
用十分鐘理解 《微分方程》
 
系統程式 -- 前言
系統程式 -- 前言系統程式 -- 前言
系統程式 -- 前言
 
系統程式 -- 附錄
系統程式 -- 附錄系統程式 -- 附錄
系統程式 -- 附錄
 
系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作系統程式 -- 第 12 章 系統軟體實作
系統程式 -- 第 12 章 系統軟體實作
 
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
 
系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統系統程式 -- 第 10 章 作業系統
系統程式 -- 第 10 章 作業系統
 
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
 
系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器系統程式 -- 第 8 章 編譯器
系統程式 -- 第 8 章 編譯器
 
系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言系統程式 -- 第 7 章 高階語言
系統程式 -- 第 7 章 高階語言
 
系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器系統程式 -- 第 6 章 巨集處理器
系統程式 -- 第 6 章 巨集處理器
 
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入
 
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
 

Kürzlich hochgeladen

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Lecture 08 virtual machine ii

  • 1. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 1 www.nand2tetris.org Building a Modern Computer From First Principles Virtual Machine Part II: Program Control
  • 2. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 2 Where we are at: Assembler Chapter 6 H.L. Language & Operating Sys. abstract interface Compiler Chapters 10 - 11 VM Translator Chapters 7 - 8 Computer Architecture Chapters 4 - 5 Gate Logic Chapters 1 - 3 Electrical Engineering Physics Virtual Machine abstract interface Software hierarchy Assembly Language abstract interface Hardware hierarchy Machine Language abstract interface Hardware Platform abstract interface Chips & Logic Gates abstract interface Human Thought Abstract design Chapters 9, 12
  • 3. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 3 The big picture . . . RISC machine VM language other digital platforms, each equipped with its VM implementation RISC machine language Hack computer Hack machine language CISC machine language CISC machine . . . written in a high-level language Any computer . . . VM implementation over CISC platforms VM imp. over RISC platforms VM imp. over the Hack platform VM emulator Some Other language Jack language Some compiler Some Other compiler Jack compiler . . .Some language . . . Chapters 1-6 Chapters 7-8 Chapters 9-13 A Java-based emulator is included in the course software suite Implemented in Projects 7-8
  • 4. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 4 The VM langauge Goal: Complete the specification and implementation of the VM model and language Method: (a) specify the abstraction (model’s constructs and commands) (b) propose how to implement it over the Hack platform. Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) previous lecture this lecture
  • 5. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 5 The compilation challenge class Main { static int x; function void main() { // Inputs and multiplies two numbers var int a, b, c; let a = Keyboard.readInt(“Enter a number”); let b = Keyboard.readInt(“Enter a number”); let c = Keyboard.readInt(“Enter a number”); let x = solve(a,b,c); return; } } // Solves a quadearic equation (sort of) function int solve(int a, int b, int c) { var int x; if (~(a = 0)) x=(-b+sqrt(b*b–4*a*c))/(2*a); else x=-c/b; return x; } } class Main { static int x; function void main() { // Inputs and multiplies two numbers var int a, b, c; let a = Keyboard.readInt(“Enter a number”); let b = Keyboard.readInt(“Enter a number”); let c = Keyboard.readInt(“Enter a number”); let x = solve(a,b,c); return; } } // Solves a quadearic equation (sort of) function int solve(int a, int b, int c) { var int x; if (~(a = 0)) x=(-b+sqrt(b*b–4*a*c))/(2*a); else x=-c/b; return x; } } Source code (high-level language) Our ultimate goal: Translate high-level programs into executable code. Compiler 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 ... 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 ... Target code
  • 6. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 6 The compilation challenge / two-tier setting if (~(a = 0)) x = (-b+sqrt(b*b–4*a*c))/(2*a) else x = -c/b if (~(a = 0)) x = (-b+sqrt(b*b–4*a*c))/(2*a) else x = -c/b Jack source code push a push 0 eq if-goto elseLabel push b neg push b push b call mult push 4 push a call mult push c call mult call sqrt add push 2 push a call mult div pop x goto contLable elseLabel: push c neg push b call div pop x contLable: push a push 0 eq if-goto elseLabel push b neg push b push b call mult push 4 push a call mult push c call mult call sqrt add push 2 push a call mult div pop x goto contLable elseLabel: push c neg push b call div pop x contLable: Compiler VM (pseudo) code 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010010 1110001100000001 ... 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 0000000000010010 1110001100000001 ... VM translator Machine code We’ll develop the compiler later in the course We now turn to describe how to complete the implementation of the VM language That is -- how to translate each VM command into assembly commands that perform the desired semantics.
  • 7. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 7 // Computes x = (-b + sqrt(b^2 -4*a*c)) / 2*a if (~(a = 0)) x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a) else x = - c / b // Computes x = (-b + sqrt(b^2 -4*a*c)) / 2*a if (~(a = 0)) x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a) else x = - c / b Typical compiler’s source code input: The compilation challenge arithmetic expressions function call and return logic boolean expressions program flow logic (branching) How to translate such high-level code into machine language? In a two-tier compilation model, the overall translation challenge is broken between a front-end compilation stage and a subsequent back-end translation stage In our Hack-Jack platform, all the above sub-tasks (handling arithmetic / boolean expressions and program flow / function calling commands) are done by the back-end, i.e. by the VM translator. (previous lecture)(previous lecture)(this lecture) (this lecture)
  • 8. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 8 Lecture plan Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) previous lecture
  • 9. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 9 Program flow commands in the VM language How to translate these three abstractions into assembly? Simple: label declarations and goto directives can be effected directly by assembly commands More to the point: given any one of these three VM commands, the VM Translator must emit one or more assembly commands that effects the same semantics on the Hack platfrom How to do it? see project 8. label c // label declaration goto c // unconditional jump to the // VM command following the label c if-goto c // pops the topmost stack element; // if it’s not zero, jumps to the // VM command following the label c label c // label declaration goto c // unconditional jump to the // VM command following the label c if-goto c // pops the topmost stack element; // if it’s not zero, jumps to the // VM command following the label c In the VM language, the program flow abstraction is delivered using three commands: VM code example: function mult 1 push constant 0 pop local 0 label loop push argument 0 push constant 0 eq if-goto end push argument 0 push 1 sub pop argument 0 push argument 1 push local 0 add pop local 0 goto loop label end push local 0 return function mult 1 push constant 0 pop local 0 label loop push argument 0 push constant 0 eq if-goto end push argument 0 push 1 sub pop argument 0 push argument 1 push local 0 add pop local 0 goto loop label end push local 0 return
  • 10. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 10 Lecture plan Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Arithmetic / Boolean commands add sub neg eq gt lt and or not Memory access commands pop x (pop into x, which is a variable) push y (y being a variable or a constant) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) Program flow commands label (declaration) goto (label) if-goto (label) Function calling commands function (declaration) call (a function) return (from a function) previous lecture
  • 11. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 11 Subroutines Subroutines = a major programming artifact Basic idea: the given language can be extended at will by user-defined commands ( aka subroutines / functions / methods ...) Important: the language’s primitive commands and the user-defined commands have the same look-and-feel This transparent extensibility is the most important abstraction delivered by high-level programming languages The challenge: implement this abstraction, i.e. allow the program control to flow effortlessly between one subroutine to the other “A well-designed system consists of a collection of black box modules, each executing its effect like magic” (Steven Pinker, How The Mind Works) // Compute x = (-b + sqrt(b^2 -4*a*c)) / 2*a if (~(a = 0)) x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a) else x = - c / b // Compute x = (-b + sqrt(b^2 -4*a*c)) / 2*a if (~(a = 0)) x = (-b + sqrt(b * b – 4 * a * c)) / (2 * a) else x = - c / b
  • 12. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 12 Subroutines in the VM language The invocation of the VM’s primitive commands and subroutines follow exactly the same rules: The caller pushes the necessary argument(s) and calls the command / function for its effect The called command / function is responsible for removing the argument(s) from the stack, and for popping onto the stack the result of its execution. function mult 1 push constant 0 pop local 0 // result (local 0) = 0 label loop push argument 0 push constant 0 eq if-goto end // if arg0 == 0, jump to end push argument 0 push 1 sub pop argument 0 // arg0-- push argument 1 push local 0 add pop local 0 // result += arg1 goto loop label end push local 0 // push result return function mult 1 push constant 0 pop local 0 // result (local 0) = 0 label loop push argument 0 push constant 0 eq if-goto end // if arg0 == 0, jump to end push argument 0 push 1 sub pop argument 0 // arg0-- push argument 1 push local 0 add pop local 0 // result += arg1 goto loop label end push local 0 // push result return Called code, aka “callee” (example) ... // computes (7 + 2) * 3 - 5 push constant 7 push constant 2 add push constant 3 call mult push constant 5 sub ... ... // computes (7 + 2) * 3 - 5 push constant 7 push constant 2 add push constant 3 call mult push constant 5 sub ... Calling code (example) VM subroutine call-and-return commands
  • 13. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 13 Function commands in the VM language Q: Why this particular syntax? A: Because it simplifies the VM implementation (later). function g nVars // here starts a function called g, // which has nVars local variables call g nArgs // invoke function g for its effect; // nArgs arguments have already been pushed onto the stack return // terminate execution and return control to the caller function g nVars // here starts a function called g, // which has nVars local variables call g nArgs // invoke function g for its effect; // nArgs arguments have already been pushed onto the stack return // terminate execution and return control to the caller
  • 14. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 14 Function call-and-return conventions function mult 1 push constant 0 pop local 0 // result (local 0) = 0 label loop ... // rest of code ommitted label end push local 0 // push result return function mult 1 push constant 0 pop local 0 // result (local 0) = 0 label loop ... // rest of code ommitted label end push local 0 // push result return called function aka “callee” (example) function demo 3 ... push constant 7 push constant 2 add push constant 3 call mult ... function demo 3 ... push constant 7 push constant 2 add push constant 3 call mult ... Calling function Call-and-return programming convention The caller must push the necessary argument(s), call the callee, and wait for it to return Before the callee terminates (returns), it must push a return value At the point of return, the callee’s resources are recycled, the caller’s state is re-instated, execution continues from the command just after the call Caller’s net effect: the arguments were replaced by the return value (just like with primitive commands) Behind the scene Recycling and re-instating subroutine resources and states is a major headache Some agent (either the VM or the compiler) should manage it behind the scene “like magic” In our implementation, the magic is VM / stack-based, and is considered a great CS gem. Although not obvious in this example, every VM function has a private set of 5 memory segments (local, argument, this, that, pointer) These resources exist as long as the function is running.
  • 15. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 15 The function-call-and-return protocol The caller’s view: When I start executing, my argument segment has been initialized with actual argument values passed by the caller My local variables segment has been allocated and initialized to zero The static segment that I see has been set to the static segment of the VM file to which I belong, and the working stack that I see is empty Before exiting, I must push a value onto the stack and then use the command return. When I start executing, my argument segment has been initialized with actual argument values passed by the caller My local variables segment has been allocated and initialized to zero The static segment that I see has been set to the static segment of the VM file to which I belong, and the working stack that I see is empty Before exiting, I must push a value onto the stack and then use the command return. Before calling a function g, I must push onto the stack as many arguments as needed by g Next, I invoke the function using the command call g nArgs After g returns: The arguments that I pushed before the call have disappeared from the stack, and a return value (that always exists) appears at the top of the stack All my memory segments (local, argument, this, that, pointer) are the same as before the call. Before calling a function g, I must push onto the stack as many arguments as needed by g Next, I invoke the function using the command call g nArgs After g returns: The arguments that I pushed before the call have disappeared from the stack, and a return value (that always exists) appears at the top of the stack All my memory segments (local, argument, this, that, pointer) are the same as before the call. The callee’s (g ‘s) view: Blue = VM function writer’s responsibility Black = black box magic, delivered by the VM implementation Thus, the VM implementation writer must worry about the “black operations” only. function g nVars call g nArgs return function g nVars call g nArgs return
  • 16. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 16 When function f calls function g, the VM implementation must: Save the return address within f ‘s code: the address of the command just after the call Save the virtual segments of f Allocate, and initialize to 0, as many local variables as needed by g Set the local and argument segment pointers of g Transfer control to g. When g terminates and control should return to f, the VM implementation must: Clear g ’s arguments and other junk from the stack Restore the virtual segments of f Transfer control back to f (jump to the saved return address). Q: How should we make all this work “like magic”? A: We’ll use the stack cleverly. The function-call-and-return protocol: the VM implementation view function g nVars call g nArgs return function g nVars call g nArgs return
  • 17. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 17 The implementation of the VM’s stack on the host Hack RAM Global stack: the entire RAM area dedicated to hold the stack Working stack: from SP onwards: the stack that the current function sees At any point of time, only one function (the current function) is executing; other functions may be waiting up the calling chain Shaded areas: irrelevant to the current function The current function sees only the working stack, as well as its virtual memory segments The rest of the stack holds the frozen states of all the functions up the calling hierarchy.
  • 18. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 18 Implementing the call g nArgs command Implementation: If the VM is implemented as a program that translates VM code into assembly code, the translator must emit the above logic in assembly. // In the course of implementing the code of f // (the caller), we arrive to the command call g nArgs. // we assume that nArgs arguments have been pushed // onto the stack. What do we do next? // We generate a symbol, let’s call it returnAddress; // Next, we effect the following logic: push returnAddress // saves the return address push LCL // saves the LCL of f push ARG // saves the ARG of f push THIS // saves the THIS of f push THAT // saves the THAT of f ARG = SP-nArgs-5 // repositions SP for g LCL = SP // repositions LCL for g goto g // transfers control to g returnAddress: // the generated symbol // In the course of implementing the code of f // (the caller), we arrive to the command call g nArgs. // we assume that nArgs arguments have been pushed // onto the stack. What do we do next? // We generate a symbol, let’s call it returnAddress; // Next, we effect the following logic: push returnAddress // saves the return address push LCL // saves the LCL of f push ARG // saves the ARG of f push THIS // saves the THIS of f push THAT // saves the THAT of f ARG = SP-nArgs-5 // repositions SP for g LCL = SP // repositions LCL for g goto g // transfers control to g returnAddress: // the generated symbol call g nArgscall g nArgs None of this code is executed yet ... At this point we are just generating code (or simulating the VM code on some platform)
  • 19. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 19 Implementing the function g nVars command Implementation: If the VM is implemented as a program that translates VM code into assembly code, the translator must emit the above logic in assembly. function g nVarsfunction g nVars // to implement the command function g nVars, // we effect the following logic: g: repeat nVars times: push 0 // to implement the command function g nVars, // we effect the following logic: g: repeat nVars times: push 0
  • 20. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 20 Implementing the return command Implementation: If the VM is implemented as a program that translates VM code into assembly code, the translator must emit the above logic in assembly. // In the course of implementing the code of g, // we arrive to the command return. // We assume that a return value has been pushed // onto the stack. // We effect the following logic: frame = LCL // frame is a temp. variable retAddr = *(frame-5) // retAddr is a temp. variable *ARG = pop // repositions the return value // for the caller SP=ARG+1 // restores the caller’s SP THAT = *(frame-1) // restores the caller’s THAT THIS = *(frame-2) // restores the caller’s THIS ARG = *(frame-3) // restores the caller’s ARG LCL = *(frame-4) // restores the caller’s LCL goto retAddr // goto returnAddress // In the course of implementing the code of g, // we arrive to the command return. // We assume that a return value has been pushed // onto the stack. // We effect the following logic: frame = LCL // frame is a temp. variable retAddr = *(frame-5) // retAddr is a temp. variable *ARG = pop // repositions the return value // for the caller SP=ARG+1 // restores the caller’s SP THAT = *(frame-1) // restores the caller’s THAT THIS = *(frame-2) // restores the caller’s THIS ARG = *(frame-3) // restores the caller’s ARG LCL = *(frame-4) // restores the caller’s LCL goto retAddr // goto returnAddress returnreturn
  • 21. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 21 Bootstrapping SP = 256 // initialize the stack pointer to 0x0100 call Sys.init // call the function that calls Main.main SP = 256 // initialize the stack pointer to 0x0100 call Sys.init // call the function that calls Main.main A high-level jack program (aka application) is a set of class files. By a Jack convention, one class must be called Main, and this class must have at least one function, called main. The contract: when we tell the computer to execute a Jack program, the function Main.main starts running Implementation: After the program is compiled, each class file is translated into a .vm file The operating system is also implemented as a set of .vm files (aka “libraries”) that co-exist alongside the program’s .vm files One of the OS libraries, called Sys.vm, includes a method called init. The Sys.init function starts with some OS initialization code (we’ll deal with this later, when we discuss the OS), then it does call Main.main Thus, to bootstrap, the VM implementation has to effect (e.g. in assembly), the following operations:
  • 22. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 22 Extends the VM implementation described in the last lecture (chapter 7) The result: a single assembly program file with lots of agreed-upon symbols: VM implementation over the Hack platform
  • 23. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 23 Proposed API
  • 24. Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 8: Virtual Machine, Part II slide 24 Perspective Benefits of the VM approach Code transportability: compiling for different platforms requires replacing only the VM implementation Language inter-operability: code of multiple languages can be shared using the same VM Common software libraries Code mobility: Internet Some virtues of the modularity implied by the VM approach to program translation: Improvements in the VM implementation are shared by all compilers above it Every new digital device with a VM implementation gains immediate access to an existing software base New programming languages can be implemented easily using simple compilers . . . VM language RISC machine language Hack CISC machine language . . . written in a high-level language . . . VM implementation over CISC platforms VM imp. over RISC platforms TranslatorVM emulator Some Other language Jack Some compiler Some Other compiler compiler . . .Some language . . . Benefits of managed code: Security Array bounds, index checking, … Add-on code Etc. VM Cons Performance.