Chapter 7- Stack Arithmetic Flashcards

1
Q

The vim language has what kind of data type?

A

It has one 16 bit data type that can be used as integer, Boolean or pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the formats of vm command?

A

There are 3 formats

  1. Command (add)
  2. Command ARG (goto loop)
  3. Command arg1 arg2 ( push local 3)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many arithmetic commands are there?

A

Add, sub, neg, eq, gt, lt, and, or, not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are all the memory segments?

A

Argument, local, static, constant, this, that, pointer, temp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the memory access commands?

A

Push segment index //push the value of segment[index] into stack
Pop segment index // pop the topmost element into segment[index]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If I have a foo.vm file with 3 functions, what is the memory distribution?

A

Local, argument, this, that, pointer for each function. Static is shared between all the functions. Temp and constant are program wised

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the memory distribution of the hack?

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the 16 virtual registers?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to do memory segment mapping from vm to asm?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does access to pointer memory should be decoded?

A

Pointer i should be treated as access RAM[3 +i]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does access to temp should be decoded?

A

temp i should be RAM[5 + i]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to write arithmetic command?

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When implementing a call xxx operation, what is the return address?

A

The address of the next command in the caller’s code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 3 program flow commands in the vm?

A

Label label
Goto label
If-goto label

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the label label command?

A

His command labels the current location in the function’s code. Only label locations can be jumped to from other parts of the program? The scope is the function where it is defined

17
Q

What is goto label command?

A

Effects an unconditional goto operation, causing execution to continue from the location marked by the label. The jump destination must be located at the same function

18
Q

What is if-goto label command?

A

The stack topmost element is popped. If the value is not zero, execution continues from the location marked by the label

19
Q

Method bar in class foo in jack language will be compiled to?

A

To a vm function named foo.bar

20
Q

What are the 3 function related commands?

A

Function f n
Call f m
Return

21
Q

What is the function

Function f n?

A

Here starts the code of a function named f that has n local variables.
Implemantation:
Repeat n times:
PUSH 0

22
Q

What is the function

Call f m?

A
Call function f, stating that m arguments have already been pushed onto the stack by the caller
Implementation:
Push return-address 
Push LCL
Push ARG
push THIS
push THAT
ARG = sp - m -5 //in order to reposition ARG TO THE called func
LCL = sp
Goto f
(return address)
23
Q

What is the function
Return?
FIX THIS PAGE 164

A
Return to the calling function
Implementation:
FRAME =LCL // frame is temporary
RET = *(FRAME - 5)
*ARG = pop()
Sp = ARG + 1
THAT = *(FRAME - 1)
24
Q

What is the protocol of the calling function?

A
  1. The caller has to push as many arguments as needed
  2. The caller invokes the function using the call command
  3. After the called function has returned, the arguments that the caller pushed are no longer in the stack and the topmost element is the return parameter
  4. After the called function returns, the caller’s memory segments argument, local, static,this,that,pointer are the same as they were and the temp segment is undefined!
25
Q

What is the called function protocol?

A

When it starts, it’s argument segment is already initialized with actual values and it’s local variables segment has been allocated and init to zeros.

  1. The static segments the static segment of the vm file and the working stack is empty
  2. The segments this, that, pointer and temp are undefined
  3. Before return the called function must push an element into the stack
26
Q

What is a must to start a vm program?

A

Each vm program has to have Sys.init function.