what does SP, LCL, ARG represent?

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

what does SP, LCL, ARG represent?

moonwalk
I searched on the internet, it seems SP represents stack pointer,(LCL represents local control limit?), and ARG represents argument.
I don't get the link between the name and their function.

I know they are symbols to indicate the first three addresses in RAM. I want to have a general idea why they have such a name and facilitate my memory and understanding.
Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: what does SP, LCL, ARG represent?

ybakos
As you go deeper into building the software stack, you will see first hand about their names and meaning.

In short, LCL represents the base address of the first local variable in a function's scope. ARG represents the address of the first argument passed to a function.

Their values will change every time a function is called, and returns.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: what does SP, LCL, ARG represent?

cadet1620
Administrator
In reply to this post by moonwalk
You might want to jump ahead and take a quick look at chapter 7. That's where the Virtual Machine is introduced.

The Virtual Machine has memory segments named local, argument, this, and that. When a VM language program (which is generated by the Jack compiler) is translated into Hack assembly language, the LCL, ARG, THIS, and THAT memory locations will be used by the ASM code that implements the local, argument, this, and that virtual memory segments.

I you are curious, nand2tetris/projects/06/pong/Pong.asm is a Jack program that has been translated to Hack assembly language.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: what does SP, LCL, ARG represent?

moonwalk
Thank you, ybakos and Mark! Your replies help me a lot!
Loading...