The Stack Flashcards
ARMv8 uses ______ addresses
64-bit
The ARMv8 can address ____ bytes of memory
2^64
The virtual memory space is mapped to physical memory by __ and ________
OS and Hardware
A register can be loaded with _,_,_ or _ byte data from RAM Where is data placed? If necessary, higher order bits are?
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)
Which kind of data can be stored into RAM?
byte, halfword, word, or doubleword Low-order bit of a register when the data is just a part of a register
Which part of a register can be stored in RAM when the data is just a part of the register?
Low-order bit (Right most bit) of a register
What is stack memory?
It is the space in RAM provided by the OS to store data for functions
What happens when a function is called?
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
The stack uses ____ memory
high
The stack grows _________
backwards (toward 0) low OS Program
Where are programs loaded?
Into low memory, right above the space reserved for the OS
The ____ is used for dynamically allocated memory in a program It is Done in C using ______( ) and ______( )
heap malloc freeze
Where does the SP register point and what happens to it when the stack grows?
Points to the top of the stack Is decremented when the stack grows
How is stack memory allocated by a program?
sub sp,sp,16 16 is the bytes needed
Why should the stack be quadword aligned?
The address in SP must be evenly divisible by 16 May need to allocate more space than actually needed
To guarantee alignment:
Add a negative number instead of subtracting Clear the low 4 bits of this number: AND it with -16 (1111 … 11110000)
To allocate 20 bytes:
add sp,sp,-20&-16 Actually allocates 32 bytes
What is the FP used for
To point to local variables in a stack frame
Stability of FP and SP
FP is stable, once set at the beginning of a function SP is unstable as it is allowed to change as the function executes
A ___________ is pushed onto the stack when entering a function and it should be ________ long
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 …
What does the stp do? What’s this part of the stack frame called?
Stores the contents of x29 (FP) and x30 (LR) to these 16 bytes This part of the stack frame is called the frame record
What does mov do?
Sets x29 (FP) to point to the frame record
What does the ldp do?
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
How are stack variables created?
By allocating extra space in the stack frame when entering a function (in addition to frame record’s 16 bytes)
How are stack variables addressed?
Where are addresses specified?
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:
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
Load Instructions
Store Instructions
The following are possible for basic load/store instructions:
M4 macros are used for offsets to _______________
Can also be done with _____________
____________ are useful for renaming x29 and x30 to FP and LR
improve readability (e.g. define(a_s, 16))
assembler equates(e.g. a_s = 16)
register equates (e.g. fp .reqx29)
How are local variables declared in C?
in a block of code { … }
Any inside {} are local to that
How are local variables implemented in assembly?
As stack variables