Implement Subprograms Flashcards
Subroutine linkage
Subroutine call and return operations
Implementation of subroutines must be based on ….
Semantics of the subroutine linkage
Semantics of a subroutine call (4)
(1) save the execution status of the current Program unit
(2) pass the Parameters
(3) pass the return address to the callee
(4) transfer control to the callee
Subroutine return:
If there are pass-by-value-result or out-mode parameters, the current values of those parameters are move to …
The corresponding actual parameters
Subroutine return:
Move the return value to…
A place accessible to the caller
Subroutine return:
Execution status of the caller is …
Returned
Subroutine return:
Control is transferred …
Back to the caller
Storage:
Call and return actions require storage for … (5)
Status information about the caller, parameters, return address, return value for functions, and local variables
“Simple” subroutines are
Those that cannot be nested and all local variables are static.
A simple subroutine consists of two parts: (give def for each to/size)
Code and data
Code: constant (instruction space)
Data: can change when the subroutine is executed (data space)
Both have fixed size
Activation record is
The format or layout of the data part because the data is relevant to an activation, execution, of the subroutine
The formation of an activation record is
Static
An activation record instance is a
Concrete example of an activation record corresponding to one execution
An activation record for a simple subroutine
What does the stack look like, size, allocation type, side note
Local var
Params
Return Add
Fixed size (statically allocated)
Could be attached to the code part of the sub Program
When each programming unit is compiling is it
Machine code along with a list of references to external sub programs are written to a file
A linker is called for …
MAIN to create an executable program
What does a linker do? (4)
Is a part of the OS
Also called loader, linker/loader, loader, link editor
Finds and loads all referenced subroutines including code and activation records into memory
Sets the target addresses of calls to those subroutines entry addresses
Call stack is
A stack data structure that stores information about the active subroutines of a Program
Also known as execution stack, control stack, runtime stack, machine stack.
Frowns downward in memory towards lower addresses and shrinks upwards
The activation record on stack is also called
Stack frame
stack pointer (sp) points to
The frame top
Frame pointer (to) points
To the frame base
Important advantage of stack dynamic local variables
Support for recursion
Comple activation record stack contents
Local variables Parameters Dynamic link Return address Stacktop
Dynamic link (control links) =
Previous sp