Unit9-StackFrames-EE357-Nazarian-Fall09

Unit9-StackFrames-EE357-Nazarian-Fall09 - University...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
University of Southern California Viterbi School of Engineering EE357 asic Organization of Computer Systems Basic Organization of Computer Systems tack Frames Stack Frames References: 1) Textbook 2) Mark Redekopp’s slide series Shahin Nazarian Fall 2009 3) Freescale documents on CF
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Stack Frames Compilers use the stack: to pass parameters to a subroutine to store the return address or storage of local variables declared in the subroutine for storage of local variables declared in the subroutine and a place to save register values Every call to a subroutine will create a data ructure called a “frame” on the stack to store structure called a frame on the stack to store this information To access this data structure on the stack, an address register pointer called the “ frame pointer ” (FP) is used in addition to the normal stack pointer (SP) Shahin Nazarian/EE357/Fall 2009 2
Background image of page 2
Stack Frames Caller’s code pushes parameters (arguments) Call to subroutine pushes RA Callee saves registers it will overwrite (including caller’s FP) Callee allocates space for local variables oid main() { Subroutines Stack Frame Local vars. callee’s stack area allee void main() { ... ans = avg(param1, param2); } RA Saved FP Saved Regs. Callee Caller int avg(int a, int b) { int temp=1; // local var’s caller’s stack area params. Main Routine’s Stack Frame Caller Callee Shahin Nazarian/EE357/Fall 2009 3 ... } Stack Frame Organization C
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Accessing Values on the Stack Stack pointer (SP) is usually used to access only the top value on the stack Saved Regs. To access parameters / arguments, we need to access values buried on the stack SP + disp. local vars. Saved FP We could try to use an offset from SP, but other push operations by the callee may hange the SP requiring variable params. RA change the SP requiring variable displacements Need a better solution caller’s stack area (its locals, saved regs.) To access parameters we could try to use ome displacement Shahin Nazarian/EE357/Fall 2009 4 some displacement [i.e. d(SP) ]
Background image of page 4
Frame Pointer Use a new pointer called Frame Pointer (FP) to point to the base of the current routines frame A6 is used as FP FP will not change during the course of b utin x uti n SP -d i sp . Saved Regs. local vars. subroutine execution Can use constant displacements from FP to access parameters or local riables FP + disp. params. RA Saved FP variables Key 1: FP doesn’t change during subroutine execution ey 2: Number of parameters and caller’s stack area (its locals, aved regs ) Key 2 Number of parameters and local variables is a known value Locals accessed @ negative disp. from FP rguments accessed @ positive disp saved regs.) Shahin Nazarian/EE357/Fall 2009 5 Arguments accessed @ positive disp.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/14/2010 for the course EE 357 at USC.

Page1 / 37

Unit9-StackFrames-EE357-Nazarian-Fall09 - University...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online