Week 13: Stack Frame & Passing Parameters Flashcards

1
Q

Computer programs and subroutines consist of

A

Data elements and procedures that operate on the data elements

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

The scope of a variable defines the

A

Range of its visibility or accessibility within a program

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

Global variables are visible…

A

from the moment they are loaded into memory to the moment the program stops running

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

Local variables and parameters are visible…

A

Within that procedure but invisible outside the procedure

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

When a language invokes a procedure , it is said to…

A

Activate the procedure

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

With each invocation of a procedure, there is an…

A

Activation record

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

Activation records contain…

A

All necessary information to execute the procedure

  • Parameters
  • Local variables
  • Return address
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The activation record is also known as the…

A

Frame

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

After an activation record has been used…

A

Executing a return from procedure deallocates or frees the storage taken up by the record

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

The stack provides…

A

A mechanism for implementing the dynamic memory allocation

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

The stack-frame is a region of

A

Temporary storage

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

At the beginning of a subroutine, the temporary storage will be

A

Pushed onto the stack

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

At the end of a subroutine, temporary storage will be

A

Popped from the stack

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

The two pointers associated with stack frames are

A

Stack Pointer, SP (r13)

Frame Pointer, FP (r11)

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

What register is the Stack Pointer?

A

r13

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

What register is the Frame Pointer?

A

r11

17
Q

What is in register 11?

A

The Frame Pointer

18
Q

What is in register 13?

A

The Stack Pointer

19
Q

The stack pointer always points to the

A

Top of the stack

20
Q

The frame pointer always points to the

A

Base of the current stack frame

21
Q

The _____ may change during procedure execution, but the ______ will not

A

The stack pointer may change during procedure execution, but the frame pointer will not

22
Q

It is strongly recommended that data in the stack frame be accessed through the

A

Frame Pointer

23
Q

Reserving memory in the stack frame is done by

A

ADDing / SUBtracting x-bytes onto the Stack Pointer

24
Q

Operations on the stack are ___ meaning….

A

Balanced, meaning if you put something onto the stack you have to remove it

25
Q

Does arm have native link and unlike instructions?

A

NO

26
Q

To create a stack frame you can…

A
  1. Push the old frame pointer onto the stack to save its value
  2. Make the frame pointer point to the bottom of the new stack frame
  3. move the stack pointer by d-bytes to create a local workplace
27
Q

At the end of a subroutine call the stack frame is collapsed by

A

MOV sp,fp ;restore the stack pointer

LDR fp,[sp] ;restore old frame pointer from the stack

ADD sp,sp,#4 ;move stack pointer down 4 bytes to
;restore stack

28
Q

To implement a program using the SP, FP, and LR…

A
29
Q

What does a function look like that is being called by a main area that uses BL and has parameters:

A
30
Q

If you store multiple the FP anf the LR, which will be put onto the stack first? If FD?

STMFD sp!, {fp, lr}

A

LR

Because it is FD, we are starting at higher memory addresses first and then descending since LDM and STM store the highest number register in the higher memory address / lowest numbered register in the lowest memory address

31
Q

To call a subroutine the following steps need to be performed…

A

Parameters need to be passed from the caller to the subroutine (can be done via the stack)

The address of the instruction after the calling instruction needs to be saved BEFORE branching (can be done using BL or the stack or both)

Inside the subroutine we must

  • Push all register values that are going to be used in the subroutine onto the stack
  • Make the FP point to the bottom of the frame by copying the value of the SP to the FP
  • Create a space inside the stack for local variables
  • Perform subroutine instructions where local variables and parameters are relative to the FP
  • At the end of the the subroutine, deallocate all created local variables
  • Pop all pushed registers but use the PC instead of LR to return

Finally in the calling program, all pushed parameters need to be popped

32
Q

You can pass a parameter to a subroutine by..

A

Value or by Reference

33
Q

What does a traditional call/return mechanism with parameters look like?

A