To make the call/return 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:
Allocation of local variables must now be integrated into the call/return 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)