2
University of Washington x86-64 Procedure Calling Convention Doubling of registers makes us less dependent on stack  Store argument in registers  Store temporary variables in registers What do we do if we have too many arguments or too many temporary variables? Winter 2013 2 Procedures and Stacks II

5
University of Washington X86-64 procedure call highlights Arguments (up to first 6) in registers  Faster to get these values from registers than from stack in memory Local variables also in registers (if there is room) callq instruction stores 64-bit return address on stack  Address pushed onto stack, decrementing %rsp by 8 No frame pointer  All references to stack frame made relative to %rsp; eliminates need to update %ebp/%rbp, which is now available for general-purpose use Functions can access memory up to 128 bytes beyond %rsp: the “red zone”  Can store some temps on stack without altering %rsp Registers still designated “caller-saved” or “callee-saved” Winter 2013 5 Procedures and Stacks II

6
University of Washington x86-64 Stack Frames Often (ideally), x86-64 functions need no stack frame at all  Just a return address is pushed onto the stack when a function call is made A function does need a stack frame when it:  Has too many local variables to hold in registers  Has local variables that are arrays or structs  Uses the address-of operator (&) to compute the address of a local variable  Calls another function that takes more than six arguments  Needs to save the state of callee-save registers before modifying them Winter 2013 6 Procedures and Stacks II

13
University of Washington x86-64 Procedure Summary Heavy use of registers (faster than using stack in memory)  Parameter passing  More temporaries since more registers Minimal use of stack  Sometimes none  When needed, allocate/deallocate entire frame at once  No more frame pointer: address relative to stack pointer More room for compiler optimizations  Prefer to store data in registers rather than memory  Minimize modifications to stack pointer Winter 2013 13 Procedures and Stacks II