CSCI 223 Midterm 2 Flashcards
3 mechanisms in procedures
- passing control (call, return)
- passing data (using either registers or memory)
- memory management (stack - allocate/deallocate)
x86-64 stack grows toward
lower memory addresses (down)
register ? contains address of top of stack
%rsp
stack operation: pushq Src
fetch (read) operand at Src), decrememt %rsp by 8 (or 4 on 32-bit), write operand at address given by %rsp
register ? contains address of the frame pointer
%rbp
stack operation: popq Dest
read value at address given by %rsp, increment %rsp by 8 (or 4 on 32-bit machine), store value at Dest (must be register)
procedure control flow
use stack
procedure call: push return address on stack, jump to label
procedure ret: pop address from stack, jump to address
return address
address of the next instruction right after call
return value
%rax (64-bit) or %eax (32-bit)
stack allocated in ?
frames (state for single procedure instantiation)
contents of stack frames
return information, local storage (if needed), temporary storage (if needed)
management of stack frames
space allocated when enter procedure (“set-up” code; includes push by call instruction) and deallocated when return (“finish” code; includes pop by ret instruction)
we create a new stack frame when
we enter a new function
calling conventions
caller saved and callee saved
caller saved
caller saves temporary values in its frame before the call
callee saved
callee saves temporary values in its frame before using, then restores them before returning to caller
%rax is the ?, ?-saved, and can be modified by ?
return value, caller-saved, procedure
%rdi…%r9 are the ?, ?-saved, and can be modified by ?
arguments, caller-saved, procedure
%r10, %r11 are ?-saved, and can be modified by ?
caller-saved, procedure
%rbx, %r12, %r13, %r14 are ?-saved, and can be modified by ?
caller-saved, callee must save and restore
%rbp is the ?, ?-saved, and can be modified by ?
frame pointer, callee-saved, callee must save and restore
%rsp is the ?, ?-saved, and can be modified by ?
stack pointer, callee-saved (special form), restored to original value upon exit from procedure
recursion is handled by ? calling conventions
normal (in the use of the stack)
char/unsigned char
1 byte
2^8 (256) numbers