A Question about SP register

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

A Question about SP register

narlinen
My English is poor,I will try my best to describe my question.

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
M=D
@SP
M=M+1
"

But I don't know what is the initialize of the SP Register.
I don't know what is "M" in "line 4".

The book "The Elements of Computing Systems" write "(base+i)" in chapter7.

I don't know what is "base".

Thank you
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A Question about SP register

narlinen
I read some ohter books,It seems that there are some RAM for the stack.
for example, the RAM 10000H~1000FH are used for stack.
and this stack have a base address 1000FH.

I think that the Nand2Tetris,the SP register would be stored the stack bass address.
but I don't konw what's the address.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A Question about SP register

cadet1620
Administrator
In reply to this post by narlinen
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A Question about SP register

narlinen
I got it!
Thank you very much!
Loading...