lecture6

Lecture6 - Machine-Level Programming III Procedures Machine-Level Programming III Procedures Topics Topics& IA32 stack discipline& Register

Info iconThis preview shows pages 1–10. 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: Machine-Level Programming III: Procedures Machine-Level Programming III: Procedures Topics Topics & IA32 stack discipline & Register saving conventions & Creating pointers to local variables – 2 – IA32 Stack IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Register %esp indicates lowest stack address address of top element Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” – 3 – IA32 Stack Pushing IA32 Stack Pushing Pushing Pushing & pushl Src & Fetch operand at Src & Decrement %esp by 4 & Write operand at address given by %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” Stack Pointer %esp-4 – 4 – IA32 Stack Popping IA32 Stack Popping Popping Popping & popl Dest & Read operand at address given by %esp & Increment %esp by 4 & Write to Dest Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” +4 – 5 – Procedure Control Flow Procedure Control Flow & Use stack to support procedure call and return Procedure call: Procedure call: call label Push return address on stack; Jump to label Return address value Return address value & Address of instruction beyond call & Example from disassembly 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax ¡ Return address = 0x8048553 Procedure return: Procedure return: & ret Pop address from stack; Jump to address – 6 – Stack-Based Languages Stack-Based Languages Languages that Support Recursion Languages that Support Recursion & e.g., C, Pascal, Java & Code must be “ Reentrant ” ¡ Multiple simultaneous instantiations of single procedure & Need some place to store state of each instantiation ¡ Arguments ¡ Local variables ¡ Return pointer Stack Discipline Stack Discipline & State for given procedure needed for limited time ¡ From when called to when return & Callee returns before caller does Stack Allocated in Stack Allocated in Frames Frames & state for single procedure instantiation – 7 – Call Chain Example Call Chain Example Code Structure Code Structure yoo(…) { • • who(); • • } who(…) { • • • amI(); • • • amI(); • • • } amI(…) { • • amI(); • • } yoo who amI amI amI Call Chain & Procedure amI recursive amI – 8 – Stack Pointer %esp yoo who proc Frame Pointer %ebp Stack “Top” Stack Frames Stack Frames Contents Contents & Local variables & Return information & Temporary space Management Management & Space allocated when enter procedure ¡ “Set-up” code & Deallocated when return ¡ “Finish” code Pointers Pointers & Stack pointer %esp indicates stack top & Frame pointer %ebp indicates start of current frame amI – 9 – Stack Pointer %esp yoo • • • Frame Pointer %ebp Stack Operation Stack Operation yoo Call Chain yoo(…) { • • who(); • • } – 10 –...
View Full Document

This note was uploaded on 04/13/2008 for the course CS 211 taught by Professor Chakraborty during the Spring '08 term at Rutgers.

Page1 / 40

Lecture6 - Machine-Level Programming III Procedures Machine-Level Programming III Procedures Topics Topics& IA32 stack discipline& Register

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

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