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
Q

What is dynamic link used for?

A

In destruction of the current activation record instance when the procedure completes its execution

26
Q

What does the dynamic link restore?

A

The sp in the previous frame (caller)

27
Q

What is a collection of dynamic links in the stack at a given time called? And what do the represent?

A

Called dynamic chain (call chain)

Represents the dynamic history of how execution got to its current position

28
Q

What is the purpose of a dynamic link?

A

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
Q

Local scalar variables are bound to

A

Storage within an activation record instance

30
Q

Local variables that are structures are sometimes allocate elsewhere and only leave their …

A

Descriptors and a pointer to the storage as a part of their activation record

31
Q

Recursion adds the possibility of multiple …

A

Simultaneous activations of a subroutine at a given time with atleast one call from outside the subroutine and one or more recursive calls.

32
Q

Each recursion activation requires

A

It’s own activation record instance

33
Q

What static scoped languages use stack dynamic local variables and allow subroutine to be nested?

A

Fortran, ada, Python, JavaScript

34
Q

Finding access to non local variables in nested subroutines of static scoped Lang but stack dynamic local variables

A

(1) find activation record instance on the stack where variable is allocation
(2) local-offset of the variables to access it

35
Q

Local offset describes the …

A

Offset from the beginning/bottom of an activation record

36
Q

Finding activation record instance:

Static chaining (3)

A

(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
Q

Activation record instance with static link stack

A
Local variables 
Parameters 
Dynamic link 
Static link 
Return address
38
Q

A static chain is a chain of

A

Static links that connect the activation record instances of all static ancestors for an executing subroutine

39
Q

Static chain can be used to implement

A

No local variable access

40
Q

Static_depth and nesting_depth difference

A

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