Lecture10

Lecture10 - Assembly Programming II Assembly Programming II...

Info iconThis preview shows pages 1–12. 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

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: Assembly Programming II Assembly Programming II Topics s IA32 stack discipline s Register saving conventions s Creating pointers to local variables IA32 Stack IA32 Stack s Region of memory managed with stack discipline s Grows toward lower addresses s Register %esp indicates lowest stack address c address of top element Stack Pointer %esp Stack Grows Down Increasing Addresses Stack Top Stack Bottom IA32 Stack Pushing IA32 Stack Pushing Pushing s pushl Src s Fetch operand at Src s Decrement %esp by 4 s Write operand at address given by %esp Stack Grows Down Increasing Addresses Stack Top Stack Bottom Stack Pointer %esp-4 IA32 Stack Popping IA32 Stack Popping Popping s popl Dest s Read operand at address given by %esp s Increment %esp by 4 s Write to Dest Stack Pointer %esp Stack Grows Down Increasing Addresses Stack Top Stack Bottom +4 %esp %eax %edx %esp %eax %edx %esp %eax %edx 0x104 555 0x108 0x108 0x10c 0x110 0x104 555 213 213 123 Stack Operation Examples Stack Operation Examples 0x108 0x10c 0x110 555 213 123 0x108 0x104 pushl %eax 0x108 0x10c 0x110 213 123 0x104 213 popl %edx 0x108 213 Procedure Control Flow Procedure Control Flow s Use stack to support procedure call and return Procedure call: call label Push return address on stack; Jump to label Return address value s Address of instruction beyond call s Example from disassembly 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax c Return address = 0x8048553 Procedure return: s ret Pop address from stack; Jump to address %esp %eip %esp %eip 0x804854e 0x108 0x108 0x10c 0x110 0x104 0x804854e 0x8048553 123 Procedure Call Example Procedure Call Example 0x108 0x10c 0x110 123 0x108 call 8048b90 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax 0x8048b90 0x104 %eip is program counter %esp %eip 0x104 %esp %eip 0x8048591 0x8048591 0x104 0x104 0x108 0x10c 0x110 0x8048553 123 Procedure Return Example Procedure Return Example 0x108 0x10c 0x110 123 ret 8048591: c3 ret 0x108 %eip is program counter 0x8048553 0x8048553 Stack-Based Languages Stack-Based Languages Languages that Support Recursion s e.g., C, Pascal, Java s Code must be Reentrant c Multiple simultaneous instantiations of single procedure s Need some place to store state of each instantiation c Arguments c Local variables c Return pointer Stack Discipline s State for given procedure needed for limited time c From when called to when return s Callee returns before caller does Stack Allocated in Frames s state for single procedure instantiation Call Chain Example Call Chain Example Code Structure yoo() { who(); } who() { amI(); amI(); } amI() { amI(); } yoo who amI amI amI Call Chain s Procedure amI recursive amI Stack Pointer %esp yoo who proc Frame Pointer %ebp Stack Top Stack Frames Stack Frames Contents s Local variables s Return information s Temporary space Management s Space allocated when enter...
View Full Document

This document was uploaded on 10/31/2011 for the course 198 211 at Rutgers.

Page1 / 65

Lecture10 - Assembly Programming II Assembly Programming II...

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

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