Simple Procedure Call and Return
- parameter transmission
- storage allocation/initialization
- transfer control
f(x) = x + y + f(z)
temporaries needed to hold results
Transfer Control
- Exit:
- return address retrieved and stored
- subroutine data freed
- branch to return address
- Entry:
- save return address
- save data area
Simulating Recursion
- Entry:
- declare stack
- label first executable statement L1
- Recursive Calls:
- store all parameters and local variables in stack
- create return label I and store on stack
- evaluate arguments and copy to formal parameters
- insert goto to procedure beginning
- attach label created in step 4 to statement after goto
- To handle returns:
- if empty stack then
- else:
- give output parameters values from stack top
- insert code to get return address from stack
- remove all locals from stack
- if function, insert code to evaluate expression and store result on stack
- go to the return address using goto