Architecture 05 Flashcards
What is the flags register in x86-64?
- 64 bits, but not available as general purpose register
- Individual bits reflect execution of preceding instruction
- Conditional jumps executed based on these flags
What are the individual bits of the flags register?
- bit 0 is carry flag (did add/sub result in carry bit?)
- bit 2 is parity flag (last result had even number of bits?)
- bit 6 is zero flag (last result was 0?)
- bit 7 is sign flag? (last result was negative?)
- bit 11 is overflow flag? (did add/sub result in overflow?)
What is RIP relative addressing?
- Avoids direct addressing (with an absolute address)
* Instead address is current value of rip plus displacement
What is an advantage of RIP relative addressing?
Position independent code - code that runs no matter where it is loaded in memory
What is a disadvantage of RIP relative addressing?
Displacement is limited to 32 bits
What does the conventional use of memory by a program consist of?
- Program (lowest address is here)
- Static data (variables outside functions/static variables)
- Dynamic data (heap - grows up through malloc)
- Free space (out of memory when heap meets stack)
- Stack (highest address, grows down through function calls)
What does a stack frame consist of?
- Arguments
- Local variables
- Saved registers
- Return address
Why wait until the stack and heap meet to declare there is no memory left?
Avoids setting bound on size of stack alone and setting bound on size of heap alone
What does the call of a function mainly consist of relative to the stack frame?
- Push arguments (or put in registers if possible)
- Execute callq (pushes value from rip before setting rip to new value)
- Push old value from rbp
- Set rbp to value from rsp
- Decrement rsp to make space for local variables and saved register values
What does the exit of a function mainly consist of relative to the stack frame?
- Increment rsp to free space used for local variables and saved register values
- Pop old value from rbp, putting back in rbp
- Execute retq (pops address and puts back into rip)
- Increment rsp to free space taken up by any arguments
What is the red zone?
A 128 byte area below rsp which the callee can use for temporary data without creating a new stack frame
What’s special about how arguments are passed on via the stack (not via registers)?
They are pushed on in reverse order, so the last argument is pushed first
What must be done before executing a ret instruction?
A function must load the return value into the location that the processor uses