Unit - 4 Pushdown Automata: Run Time Environments
Unit - 4 Pushdown Automata: Run Time Environments
Pushdown
Run Time Environments
Automata
▪ Static allocation
▪ lays out storage for all data objects at compile time.
▪ In static allocation, names are bound to storage as the program is
compiled, so there is no need for a run-time support package.
▪ Since the bindings do not change at run-time, every time a
procedure is activated, its names are bounded to the same storage
location.
Code area Data area for procedure A Data area for procedure B
…. Caller’s
Control link activation
Parameter and return value record
Temporaries and local data
Caller’s
Parameter and return value responsibility
Control link
Links and saved status Callee’s
top_sp activation
Temporaries and local data Callee’s record
responsibility
Chapter – 7 : Run Time Environment 17 Bahir Dar Institute of Technology
Stack allocation: Calling Sequences
▪ The calling sequence and its division between caller and callee are as follows:
1. The caller evaluates the actual parameters.
2. The caller stores a return address and the old value of top_sp into the callee’s
activation record. The caller then increments the top_sp to the respective
positions.
3. The callee saves the register values and other status information.
4. The callee initializes its local data and begins execution.
…. Caller’s
Control link activation
Parameter and return value record
Temporaries and local data
Caller’s
Parameter and return value responsibility
Control link
Links and saved status Callee’s
top_sp activation
Temporaries and local data Callee’s record
responsibility
Chapter – 7 : Run Time Environment 18 Bahir Dar Institute of Technology
Stack allocation: Calling Sequences
▪ A suitable, corresponding return sequence is:
1. The callee places the return value next to the parameters.
2. Using the information in the machine status field, the callee restores top_sp
and other registers, and then branches to the return address that the caller
placed in the status field.
3. Although top_sp has been decremented, the caller knows where the return
value is, relative to the current value of top_sp ; the caller therefore may use
that value.
…. Caller’s
Control link activation
Parameter and return value record
Temporaries and local data
Caller’s
Parameter and return value responsibility
Control link
Links and saved status Callee’s
top_sp activation
Temporaries and local data Callee’s record
responsibility
Chapter – 7 : Run Time Environment 19 Bahir Dar Institute of Technology
Stack allocation: Variable length data on stack
▪ The run time memory management system must deal frequently with the
allocation of objects, the sizes of which are not known at the compile time, but
which are local to a procedure and thus may be allocated on the stack.
▪ The same scheme works for objects of any type if they are local to the
procedure called have a size that depends on the parameter of the call.
Control link
Pointer to A
Pointer to B
Pointer to C
Array A
Array B
Array C
top_sp
Control link
sp
Chapter – 7 : Run Time Environment 20 Bahir Dar Institute of Technology
Stack allocation: Dangling Reference
Name n Info n