Restoring LCL and ARG after return from calee function

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

Restoring LCL and ARG after return from calee function

hemasaad
When Implement the return command in assembly from what we should do is restoring
-endframe = LCL  
-retaddress = *(endfram-5)
-*ARG = pop()
I ask the LCL pointer may be changed during the computation on the callee function so it isn't still far from the retaddress by 5 locations and also the ARG pointer may be changed on the callee function so it doesn't refer to the argument0. ARG pointer may point to argument3 before return to the caller function.
These two points I can't understand them. can anyone explain them to me?
Reply | Threaded
Open this post in threaded view
|

Re: Restoring LCL and ARG after return from calee function

cadet1620
Administrator
The ARG and LCL pointers do not change during the lifetime of the function. They always point to 'argument 0' and 'local 0'.

When the VM code references 'argument 3', for instance, the generated ASM code needs to do something like
    @3
    D=A
    @ARG
    A=M
    A=A+D   // does not change ARG
    D=M     // argument 3 in D.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Restoring LCL and ARG after return from calee function

hemasaad
Oh yes I remember ARG and LCL are static pointers not dynamic pointers points to the base address of memory segments.Thank so much