Chapter 7- Stack Arithmetic Flashcards
The vim language has what kind of data type?
It has one 16 bit data type that can be used as integer, Boolean or pointer.
What are the formats of vm command?
There are 3 formats
- Command (add)
- Command ARG (goto loop)
- Command arg1 arg2 ( push local 3)
How many arithmetic commands are there?
Add, sub, neg, eq, gt, lt, and, or, not
What are all the memory segments?
Argument, local, static, constant, this, that, pointer, temp
What are the memory access commands?
Push segment index //push the value of segment[index] into stack
Pop segment index // pop the topmost element into segment[index]
If I have a foo.vm file with 3 functions, what is the memory distribution?
Local, argument, this, that, pointer for each function. Static is shared between all the functions. Temp and constant are program wised
From jack program of two classes foo.jack and Bar.jack with methods m,n,p and m,n- what are he products of the vim to assembly to hack?
2 files Foo.vm and Bar.vm with Foo.m, Foo.n Foo.p and Bar.m and Bar.n functions. After one prog.asm file
And then prog.hack binary code
What is the memory distribution of the hack?
O-15 are 16 virtual registers // notice that everything is on the RAM! 16-255 are static variables 256-2047 is the stack 2048-16384 is the heap 16384-24575 is memory mapped I/O
What are the 16 virtual registers?
SP RAM[0], LCL RAM[1], ARG RAM[2], THIS RAM [3], THAT RAM[4].
RAM[5-12] is temp, RAM[13-15] are general purpose
How to do memory segment mapping from vm to asm?
We have the 4 virtual registers that are mapped to the RAM.
AnY entry to one of those segments should be translated as
: if to the i’th entry of LCL for example
(base + i).
How does access to pointer memory should be decoded?
Pointer i should be treated as access RAM[3 +i]
How does access to temp should be decoded?
temp i should be RAM[5 + i]
How to write arithmetic command?
Pop = @sp, AM = M-1// A = memory[0] -1..takes the sp down D=M//put the data in D If binary... @sp AM=M-1, A=M Let's say add command D=D+A Now we should push D @sp, A=M, M=D, @sp, M=M+1
When implementing a call xxx operation, what is the return address?
The address of the next command in the caller’s code.
What are the 3 program flow commands in the vm?
Label label
Goto label
If-goto label