15 Procedures - 1 Subroutines and control abstraction(Scott...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 Subroutines and control abstraction (Scott Chapter 8) 2 • Review of Allocation strategies – Static • Code • Globals • Own variables • Explicit constants (including strings, sets, other aggregates) • Small scalars may be stored in the instructions themselves – Stack • parameters • local variables • temporaries • bookkeeping information – Heap • dynamic allocation 3 4 • Contents of a stack frame – bookkeeping • return PC (dynamic link) • saved registers • line number • saved display entries • static link – arguments and returns – local variables – temporaries 5 • Maintenance of stack is responsibility of calling sequence and subroutine prolog and epilog – calling sequence : code executed in caller immediately before and after the call – subroutine prolog : code executed at the beginning of the subroutine in the routine itself – subroutine epilog : code executed at the end of the subroutine 6 • Tasks for calling sequence, prolog, epilog include – At beginning of call • pass parameters • save return address • change the program counter • change the stack pointer • save registers (including frame pointer) • change frame pointer to new frame • initialization code, as required by objects in new frame – At end of call • passing return values • execute finalization code as required • deallocate stack frame (restore stack pointer) • restore other saved registers • restore program counter 7 • Many of these tasks can be done by either caller or callee – space is saved by putting as much in the prolog and epilog as possible – time may be saved by putting stuff in the caller instead, where more information may be known • e.g., there may be fewer registers IN USE at the point of call than are used SOMEWHERE in the callee • Common strategy is to divide registers into caller-saves and callee-saves sets – caller uses the "callee-saves" registers first – "caller-saves" registers if necessary • Local variables and arguments are assigned fixed OFFSETS from the stack pointer or frame pointer at compile time – some storage layouts use a separate arguments pointer – the VAX architecture encouraged this 8 9 Example: C on MIPS • In calling sequence, the caller – saves into the temporaries and locals area any caller- saves registers whose values will be needed after the call – puts up to 4 small arguments into registers $4-$7 (a0- a3) • it depends on the types of the parameters and the order in which they appear in the argument list – puts the rest of the arguments into the arg build area at the top of the stack frame – does jal, which puts return address into register ra and branches 10 • In prolog, Callee – subtracts framesize from sp – saves callee-saves registers used anywhere inside callee – copies sp to fp • In epilog, Callee – puts return value into registers (mem if large) – copies fp into sp – restores saved registers using sp as base – adds to sp to deallocate frame – does jra 11...
View Full Document

This note was uploaded on 12/09/2009 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 101

15 Procedures - 1 Subroutines and control abstraction(Scott...

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

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