Today in CS362: Translating Function and Procedure Calls Admin * Expect phase 4 of the project on Monday Overview * Background: + Format of stack frame + Strategy for translating expressions + Phases of procedure/function call/return + Key responsibilities * Design decisions: Who is responsible for what? * Details Review: What goes in a stack frame? * Parameters to function or procedure. * Pointer to the previous stack frame. * Room for return value. * Local variables (maybe just part of the stack). * Saved register values. * Return address (potentially) * Some extra space in case we can't count correctly in figuring out what goes where on the stack. Review: Three strategies for translating expressions * translate(Exp) returns code+location * translate(Exp,result-location) returns code * hybrid Review: Caller and Callee Push parameters Push old frame pointer Push return address Push space for local variables Push space for return value (in some cases) Return to code Restore old frame pointer Observation: What our Pascal Compiler does makes it easier to read the caller. Generates less code. Counter observation: With some clever rearrangement, we could get by with one ADD instead of three. Current technique does not require the caller to know about the number of local variables required by callee. translate(ID(,,),desired_location) translate(,onstack) translate(,onstack) translate(,onstack) push return_address jump lookup(ID,address) RETURN_ADDRESS: move return-register desired-location clean up the stack .... code for procedure Setup: push frame pointer frame-pointer = stackpointer push space for local variables Body: Cleanup: stack-pointer = frame-pointer frame-pointer = pop JUMP pop