{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture10 - Assembly Programming II Topics IA32 stack...

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

View Full Document Right Arrow Icon
Assembly Programming II Topics square6 IA32 stack discipline square6 Register saving conventions square6 Creating pointers to local variables
Background image of page 1

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

View Full Document Right Arrow Icon
IA32 Stack square6 Region of memory managed with stack discipline square6 Grows toward lower addresses square6 Register %esp indicates lowest stack address circle6 address of top element Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom”
Background image of page 2
IA32 Stack Pushing Pushing square6 pushl Src square6 Fetch operand at Src square6 Decrement %esp by 4 square6 Write operand at address given by %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” Stack Pointer %esp -4
Background image of page 3

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

View Full Document Right Arrow Icon
IA32 Stack Popping Popping square6 popl Dest square6 Read operand at address given by %esp square6 Increment %esp by 4 square6 Write to Dest Stack Pointer %esp Stack Grows Down Increasing Addresses Stack “Top” Stack “Bottom” +4
Background image of page 4
%esp %eax %edx %esp %eax %edx %esp %eax %edx 0x104 555 0x108 0x108 0x10c 0x110 0x104 555 213 213 123 Stack Operation Examples 0x108 0x10c 0x110 555 213 123 0x108 0x104 pushl %eax 0x108 0x10c 0x110 213 123 0x104 213 popl %edx 0x108 213
Background image of page 5

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

View Full Document Right Arrow Icon
Procedure Control Flow square6 Use stack to support procedure call and return Procedure call: call label Push return address on stack; Jump to label Return address value square6 Address of instruction beyond call square6 Example from disassembly 804854e: e8 3d 06 00 00 call 8048b90 <main> 8048553: 50 pushl %eax circle6 Return address = 0x8048553 Procedure return: square6 ret Pop address from stack; Jump to address
Background image of page 6
%esp %eip %esp %eip 0x804854e 0x108 0x108 0x10c 0x110 0x104 0x804854e 0x8048553 123 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
Background image of page 7

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

View Full Document Right Arrow Icon
%esp %eip 0x104 %esp %eip 0x8048591 0x8048591 0x104 0x104 0x108 0x10c 0x110 0x8048553 123 Procedure Return Example 0x108 0x10c 0x110 123 ret 8048591: c3 ret 0x108 %eip is program counter 0x8048553 0x8048553
Background image of page 8
Stack-Based Languages Languages that Support Recursion square6 e.g., C, Pascal, Java square6 Code must be “ Reentrant circle6 Multiple simultaneous instantiations of single procedure square6 Need some place to store state of each instantiation circle6 Arguments circle6 Local variables circle6 Return pointer Stack Discipline square6 State for given procedure needed for limited time circle6 From when called to when return square6 Callee returns before caller does Stack Allocated in Frames square6 state for single procedure instantiation
Background image of page 9

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

View Full Document Right Arrow Icon
Call Chain Example Code Structure yoo(…) { who(); } who(…) { • • • amI(); • • • amI(); • • • } amI(…) { amI(); } yoo who amI amI amI Call Chain square6 Procedure amI recursive amI
Background image of page 10
Stack Pointer %esp yoo who proc Frame Pointer %ebp Stack “Top” Stack Frames Contents square6 Local variables square6 Return information square6 Temporary space Management square6 Space allocated when enter procedure circle6 “Set-up” code square6 Deallocated when return circle6 “Finish” code Pointers square6 Stack pointer %esp indicates stack top square6 Frame pointer %ebp indicates start of current frame amI
Background image of page 11

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

View Full Document Right Arrow Icon
Stack Pointer %esp yoo Frame Pointer %ebp Stack Operation yoo Call Chain yoo(…) { who(); }
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}