Sections


Main-Menu

header image

Local variables


In the section on parameter passing, we saw how to pass parameters from a caller to a callee and how to access those parameters during the execution of the callee.

To make the callreturn protocol complete, we also need to show how to allocte variables local to a particular subprogram. These variables are allocated on the stack. Fortunately, we already have all the architectural support we need for local variables.

We will use the following stack frame layout

local-variables1.jpg

Allocation of local variables must now be integrated into the callreturn protocol as follows

Caller Callee
—— ——

compute argument n in R1
push R1

compute argument 1 in R1
push R1
jsr callee
addsp -m (to allocate m vars)
compute return value in R0
addsp m (to deallocate vars)
ret
addsp n (to pop arguments)


Related Articles :



Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Shaadi.com Matrimony - Register for FREE