narlinen wrote
In Chapter7,I want to finish the vm code.
"push constant 6".
This vm code can be translated into the Hack asm code.
"
@6
D=A
@SP
A=M //line 4
...
"
But I don't know what is the initialize of the SP Register.
I don't know what is "M" in "line 4".
In the Nand2Tetris VM, the stack occupies addresses 256 through 2047.
In the Project 7 tests, SP is initialized in the test scripts, along with the segment pointers: ARG, LCL, THIS and THAT.
In the second half of Project 8, the SP register is initialized to 256 in the "bootstrap" code that you will be writing.
The book "The Elements of Computing Systems" write "(base+i)" in chapter7.
I don't know what is "base".
This means that for VM commands like "push local 4" you need to push the value in memory address LCL+4:
@LCL
D=M // LCL pointer value
@4
A=D+A // "local4" address
D=M
// push D
--Mark