Lecture 05 Flashcards
What is the rflags register for?
It is updated after every instruction to reflect its result. Individual bits represent whether the result was zero, negative, resulted in overflow etc.
Programs can make conditional jumps based on these flags.
What is ‘rip relative addressing’?
‘RIP relative addressing’ is when an address is computed as some displacement, plus the current value of register RIP.
This means that code will work regardless of where it is loaded into memory, but the displacement is limited to 32 bits.
The stack:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.
A - The stack starts at the top of the memory space, and grows downwards as data is added to it.
The heap:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.
B - The heap grows upwards as data is allocated to it.
For example, a malloc() call will allocate data on the heap.
Static Data:
A - Grows from the top of the memory space downwards.
B - Grows from the bottom of memory upwards.
C - Does not change size during execution.
Static data does not change size during execution.
What sort of data is held in a stack frame?
Arguments, local variables, saved registers, and the return address.
What sort of data is held in the heap?
Anything allocated using malloc(). This is usually variables that are passed between different functions.
What sort of data is held in the ‘Static Data’ section of memory?
Global variables, static variables.
Can the heap contain gaps? Why?
The heap may contain gaps as memory can be freed after it has been used, removing it from the heap.
How large is the ‘red-zone’ beneath rsp?
128 bytes
What order are arguments pushed onto the stack:
In order, or in reverse order?
Arguments are pushed onto the stack in reverse order, i.e. the last argument is pushed on first.
What are the five main steps for calling a function in assembler?
- Push arguments (or put them in registers if possible)
- Execute callq (which pushes value from rip before setting rip to a new value)
- Push old value of rbp
- Set rbp to value from rsp
- Decrement rsp to make space for local variables and saved register values.
What are the four main steps of exiting from a function in assembler?
- Increment rsp to free space used for local variables and saved register values.
- Pop old value from rbp, putting it back in rbp.
- Execution of retq (which pops address and puts it back in rip)
- Increment rsp to free space taken up by arguments