Scatman_John wrote
But the .vm files we are supposed to import to our programs don't specify anything like this, so I don't know where to put the local arguments in my "stack".
It's always relative to the address stored in LCL. You can assume that
LCL will always have an address, and that address represents the base address of the
local segment. Same for
ARG and
argument. Consider how the stack works. Your vm program never needs to "know" where the stack is - it always relies on whatever value is stored in
SP.
Consider BasicTest.vm. The first two vm instructions are:
push constant 10
pop local 0
Since LCL contains the value 300, the local segment starts at 300. So after the above two commands execute, where is 10? It should reside in address 300, the "0th" address of the local segment. How do we know this? Because LCL contains 300, and pop local 0 means take the value on the top of the stack and store it the address that is 0 plus the base address of local.
If the commands were:
push constant 10
pop local 2
Then 10 would be stored in address 302. Why?
Your goal for Project 7 is to create the ASM code that would result in these behaviors. You should have already translated push constant. For example, push constant 10 translates to "use the stack pointer to determine the address of the top of the stack, store the value 10 there, and increment the stack pointer."
What does the command pop local 2 translate to?