When a procedure calls another procedure (even itself) the state of that procedure must be saved = its activation environment must be saved. In a structured language the space for this is taken from a stack so that the runtime stack may be composed of many activation records as procedures call other procedures.
Remember that not just the return address is put on the stack
with recursion or nesting of procedures and hence deep
recursion can quickly cause a STACK OVERFLOW.
The data frame is also reclaimed from the stack.
-------------
(A) Activation (1) Pointer to current activation
Environment environment is at A.
of current (2) When procedure (2) is called, pointer
procedure moves to B and new environment is stored
------------- (3) When a return is executed the pointer
(B) Activation at B returns the pointer to (A) and
Environment "dead" environment.
-------------
Compare this with PL0.
What does a call do?
What does an OPR, 0, 0 do?
CALL:
S[T+1]BASE(L);
S[T+2]B;
S[T+3]P;
BT+1;
Pa;
OPR 0,0:
tb-1;
PS[t+3];
bs[t+2];
How does RETURN reclaim the stack data frame?
Summary of
actions for a procedure activation
CALL:
(1) Allocate space for data frame (activation record) of
called procedure/function.
(2) Process parameters appropriately and place in reserved
location in data frame (or static memory).
(3) Set up pointers to other environments to allow access to
other data frames of textually enclosing
blocks/procedures/functions.
(4) Save current environment and create new values for new
activation.
(5) Stop execution of current procedure and start new.
RETURN:
(1) STORE result in some place if function.
(2) "Reload" calling environment.
(3) Stop execution of called procedure and resume execution
of calling procedure.