Implement Subprograms Flashcards

1
Q

Subroutine linkage

A

Subroutine call and return operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Implementation of subroutines must be based on ….

A

Semantics of the subroutine linkage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Semantics of a subroutine call (4)

A

(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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Subroutine return:

If there are pass-by-value-result or out-mode parameters, the current values of those parameters are move to …

A

The corresponding actual parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Subroutine return:

Move the return value to…

A

A place accessible to the caller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Subroutine return:

Execution status of the caller is …

A

Returned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Subroutine return:

Control is transferred …

A

Back to the caller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Storage:

Call and return actions require storage for … (5)

A

Status information about the caller, parameters, return address, return value for functions, and local variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

“Simple” subroutines are

A

Those that cannot be nested and all local variables are static.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A simple subroutine consists of two parts: (give def for each to/size)

A

Code and data
Code: constant (instruction space)
Data: can change when the subroutine is executed (data space)
Both have fixed size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Activation record is

A

The format or layout of the data part because the data is relevant to an activation, execution, of the subroutine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The formation of an activation record is

A

Static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

An activation record instance is a

A

Concrete example of an activation record corresponding to one execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

An activation record for a simple subroutine

What does the stack look like, size, allocation type, side note

A

Local var
Params
Return Add

Fixed size (statically allocated)

Could be attached to the code part of the sub Program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When each programming unit is compiling is it

A

Machine code along with a list of references to external sub programs are written to a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A linker is called for …

A

MAIN to create an executable program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does a linker do? (4)

A

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

18
Q

Call stack is

A

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

19
Q

The activation record on stack is also called

A

Stack frame

20
Q

stack pointer (sp) points to

A

The frame top

21
Q

Frame pointer (to) points

A

To the frame base

22
Q

Important advantage of stack dynamic local variables

A

Support for recursion

23
Q

Comple activation record stack contents

A
Local variables 
Parameters 
Dynamic link 
Return address 
Stacktop
24
Q

Dynamic link (control links) =

A

Previous sp

25
What is dynamic link used for?
In destruction of the current activation record instance when the procedure completes its execution
26
What does the dynamic link restore?
The sp in the previous frame (caller)
27
What is a collection of dynamic links in the stack at a given time called? And what do the represent?
Called dynamic chain (call chain) Represents the dynamic history of how execution got to its current position
28
What is the purpose of a dynamic link?
Required when there are allocations from the stack by a subroutine by one it’s activation record (temporaries) Access biblical variables in dynamic scoped languages
29
Local scalar variables are bound to
Storage within an activation record instance
30
Local variables that are structures are sometimes allocate elsewhere and only leave their ...
Descriptors and a pointer to the storage as a part of their activation record
31
Recursion adds the possibility of multiple ...
Simultaneous activations of a subroutine at a given time with atleast one call from outside the subroutine and one or more recursive calls.
32
Each recursion activation requires
It’s own activation record instance
33
What static scoped languages use stack dynamic local variables and allow subroutine to be nested?
Fortran, ada, Python, JavaScript
34
Finding access to non local variables in nested subroutines of static scoped Lang but stack dynamic local variables
(1) find activation record instance on the stack where variable is allocation (2) local-offset of the variables to access it
35
Local offset describes the ...
Offset from the beginning/bottom of an activation record
36
Finding activation record instance: Static chaining (3)
(1) new ptr (static link aka static scope pointer/access links) point to bottom of activation record instance of the static parent (2) used to access non local varicela (3) static link appears below parameters on activation record
37
Activation record instance with static link stack
``` Local variables Parameters Dynamic link Static link Return address ```
38
A static chain is a chain of
Static links that connect the activation record instances of all static ancestors for an executing subroutine
39
Static chain can be used to implement
No local variable access
40
Static_depth and nesting_depth difference
Static depth: how deeply it is nested in the outermost scope for a non local reference Static depth of a variable definition is the nesting_depth/chain_depth of the reference