Stack Flashcards

1
Q

Where is stack allocated?

A

Primary memory

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

___ is pushed onto the stack when function is called

A

stack frame

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

stack uses high or low memory? which direction does the stack grow towards?

A

high, towards 0

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

what does the frame pointer do?

A

points to local variables in a stack frame

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

What size of address does ARMv8 use?

A

64 bit

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

How many bytes can ARMv8 address?

A

2^64

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

What is stack?

A

A space in RAM provided by the OS to store data for functions

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

What does the stack frame hold?

A

A function’s parameters, lvars and return values

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

What happens to the stack frame when the function returns?

A

It is popped

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

What does the stack diagram look like?

A

Check notes

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

Where are programs loaded (think of stack diagram)

A

Into low mem, just above the space for the OS

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

What is the heap used for?

A

dynamically allocated mem in a program. done in c using malloc() and free()

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

Where does the stack pointer (SP) point to and what happens to it when the stack grows?

A

The top of the stack. It is decremented when the stack grows

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

How does a program allocate stack mem?

A

By subtracting the number of bytes needed from SP

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

The stack must be ____ aligned. What does this mean?

A

Quadword. The address in SP must be evenly divisible by 16

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

How do we guarantee alignment?

A
  1. Add a negative number instead of subtracting.
  2. Clear the low order 4 bits of the negative number by ANDing it with -16
17
Q

Machine instructions for “allocate 20 bytes”. Does this actually allocate 20 bytes?

A

add sp, sp, -20 & -16
No, it allocates 32 because it ANDs -20 and -16

18
Q

What is the FP used for?

A

To point to lvars in a stack frame

19
Q

Stability of FP vs SP

A

FP is stable once set at the beginning of a function.

SP is allowed to change as the function executes

20
Q

A stack frame must be at least __ bytes long.

A

16

21
Q
A