The Stack Flashcards

1
Q

ARMv8 uses ______ addresses

A

64-bit

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

The ARMv8 can address ____ bytes of memory

A

2^64

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

The virtual memory space is mapped to physical memory by __ and ________

A

OS and Hardware

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

A register can be loaded with _,_,_ or _ byte data from RAM Where is data placed? If necessary, higher order bits are?

A

1,2,4, and 8 Data is placed into the lower-order bits Sign-extended if loading signed data (1 or 0) Zero-extended if loading unsigned data (0 only)

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

Which kind of data can be stored into RAM?

A

byte, halfword, word, or doubleword Low-order bit of a register when the data is just a part of a register

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

Which part of a register can be stored in RAM when the data is just a part of the register?

A

Low-order bit (Right most bit) of a register

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

What is stack memory?

A

It is the 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 happens when a function is called?

A

A stack frame is pushed onto the stack which holds the function’s parameters, local variables, local variables, and return values The frame is popped when the function returns

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

The stack uses ____ memory

A

high

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

The stack grows _________

A

backwards (toward 0) low OS Program

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

Where are programs loaded?

A

Into low memory, right above the space reserved for the OS

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

The ____ is used for dynamically allocated memory in a program It is Done in C using ______( ) and ______( )

A

heap malloc freeze

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

Where does the SP register point and what happens to it when the stack grows?

A

Points to the top of the stack Is decremented when the stack grows

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

How is stack memory allocated by a program?

A

sub sp,sp,16 16 is the bytes needed

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

Why should the stack be quadword aligned?

A

The address in SP must be evenly divisible by 16 May need to allocate more space than actually needed

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

To guarantee alignment:

A

Add a negative number instead of subtracting Clear the low 4 bits of this number: AND it with -16 (1111 … 11110000)

17
Q

To allocate 20 bytes:

A

add sp,sp,-20&-16 Actually allocates 32 bytes

18
Q

What is the FP used for

A

To point to local variables in a stack frame

19
Q

Stability of FP and SP

A

FP is stable, once set at the beginning of a function SP is unstable as it is allowed to change as the function executes

20
Q

A ___________ is pushed onto the stack when entering a function and it should be ________ long

A

stack frame 16 bytes It is created by the pre-increment part of the stp instructions main: stp x29,x30,[sp,-16]! mov x29, sp …

21
Q

What does the stp do? What’s this part of the stack frame called?

A

Stores the contents of x29 (FP) and x30 (LR) to these 16 bytes This part of the stack frame is called the frame record

22
Q

What does mov do?

A

Sets x29 (FP) to point to the frame record

23
Q

What does the ldp do?

A

negate the number used in stp to pop the stack frame when function returns to calling code It also restores x29 and x30 from main ( )’s frame record

24
Q

How are stack variables created?

A

By allocating extra space in the stack frame when entering a function (in addition to frame record’s 16 bytes)

25
Q

How are stack variables addressed?

Where are addresses specified?

A
26
Q

Many architectures require aligned memory access so an n-byte unit must be at an address evenly divisible by n and pad bytes are inserted to ensure this

On ARMv8, the exceptions for unaligned memory access are:

A

Addresses in SP must be quadword aligned
Frame record must be at an address divisble by 16 (otherwise, bus error)

Machine instructions must be word aligned (.balign 4)

Exclusive load/store accesses must be aligned

27
Q

Load Instructions

A
28
Q

Store Instructions

A
29
Q

The following are possible for basic load/store instructions:

A
30
Q

M4 macros are used for offsets to _______________

Can also be done with _____________

____________ are useful for renaming x29 and x30 to FP and LR

A

improve readability (e.g. define(a_s, 16))

assembler equates(e.g. a_s = 16)

register equates (e.g. fp .reqx29)

31
Q

How are local variables declared in C?

A

in a block of code { … }

Any inside {} are local to that

32
Q

How are local variables implemented in assembly?

A

As stack variables

33
Q
A