lcl Question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

lcl Question

pawdwanlearner
Ok, almost done with the virtual machine just need to iron out a few things. My question is this. The book says that when the vm translator sees the Function command such as Function Main.Fibonacci 0 it is to set to zero the amount of registers for local variables equal to the number after the name in. In this case it 0. So the question is do we still need to put in a dummy set or just go directly to the working stack.
Reply | Threaded
Open this post in threaded view
|

Re: lcl Question

cadet1620
Administrator
When the call code jumps to the function, SP and LCL should be pointing immediately after the saved THAT pointer. if the function requires n local variables, it needs to do the equivalent of n "push 0" commands to reserve and initialize the local segment.

In the case of "function foo 0", n = 0 so there are no "push 0"s. LCL and SP will still have the same value.

--Mark