HACK Virtual Machine: Stack, Control, Implementation Flashcards
Week 2.2, 2.3 (36 cards)
where does a virtual machine reside in computer strucutre
high level language & OS -> VM code -> machine language
what are the 2 compilation paradigms
- one-tier
- two-tier
what is one-tier complimation
source code -> compiler -> machine level instructions
- C/C++
pros of one-tier complimation
- generates efficient code
- can take full advantage of hardware
cons of one-tier compilation
- requires one compiler per target platform
- porting & maintaining software is time consuming
what is two-tier compilation
source code -> compiler -> intermediate code -> VM translator -> executable code
- python, java, C#
pros of two-tier compilation
- combile once, run everywher
- maximum portability
cons of two-tier compilation
- requires VM translator per target platform
- generates less efficient machine code
4 uses of a stack-based VM
- data movement
- arithmetic operations
- logical operations
- function calls
why is a stack-based VM a simpler paradigm
- no registers
- no direct RAM access
stack-based VM operations
- push
- pop
9 stack-based VM commands
- add - x + y
- sub x - y
- neg - -y
- gt - x > y
- lt - x < y
- and - x AND y
- or - x OR y
- not - NOT y
- eq - x = y
what are the 8 default segements of the HACK VM
- constant
- static
- local
- argument
- this
- that
- pointer
- temp
what is the constant segment
push constants to stack
- no pop allowed
what is the static segment
static variables seen by a function - not used
what is the local segment
a functions local variables - used for function calls
what is the argument segement
a functions arguments - used for function calls
what is the this segment
variable segment, starting at pointer[0] - used for objects/arrays
what is the that segment
variable segment, starting at pointer[0] - used for objects/arrays
what is the pointer segment
start of segments this & that
what is the temp segment
segment containing eight temporary variables
what are the 3 branching commands
- label
- goto
- if-goto
what does the label command do
defines the destenation for goto and if-goto commands
what does the goto command do
jump to execute the command just after <label></label>