yoo who Stack Pointer esp yoo FramePointer ebp Stack Operation yoo who Call

Yoo who stack pointer esp yoo framepointer ebp stack

This preview shows page 106 - 119 out of 148 pages.

yoo(…) { who(); } Stack Pointer %esp yoo Frame Pointer %ebp Stack Operation yoo who Call Chain amI amI amI amI
Image of page 106
Rutgers University Santosh Nagarakatte 107 IA32/Linux Stack Frame Current Stack Frame (“Top” to Bottom) n Parameters for function about to call l “Argument build” n Local variables l If can’t keep in registers n Saved register context n Old frame pointer Caller Stack Frame n Return address l Pushed by call instruction n Arguments for this call Stack Pointer ( %esp ) Frame Pointer ( %ebp ) Return Addr Saved Registers + Local Variables Argument Build Old %ebp Arguments Caller Frame
Image of page 107
Revisiting swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } int zip1 = 15213; int zip2 = 91125; void call_swap() { swap(&zip1, &zip2); } call_swap: • • • pushl $zip2 # Global Var pushl $zip1 # Global Var call swap • • • &zip2 &zip1 Rtn adr %esp Resulting Stack Calling swap from call_swap
Image of page 108
Revisiting swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret Body Set Up Finish
Image of page 109
swap Setup #1 swap: pushl %ebp movl %esp,%ebp pushl %ebx Resulting Stack &zip2 &zip1 Rtn adr %esp Entering Stack %ebp yp xp Rtn adr Old %ebp %ebp %esp
Image of page 110
swap Setup #2 swap: pushl %ebp movl %esp,%ebp pushl %ebx yp xp Rtn adr Old %ebp %ebp Resulting Stack &zip2 &zip1 Rtn adr %esp Entering Stack %ebp %esp
Image of page 111
swap Setup #3 swap: pushl %ebp movl %esp,%ebp pushl %ebx yp xp Rtn adr Old %ebp %ebp Resulting Stack &zip2 &zip1 Rtn adr %esp Entering Stack %ebp Old %ebx %esp
Image of page 112
Effect of swap Setup yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset (relative to %ebp ) Resulting Stack &zip2 &zip1 Rtn adr %esp Entering Stack %ebp Old %ebx %esp movl 12(%ebp),%ecx # get yp movl 8(%ebp),%edx # get xp . . . Body
Image of page 113
Rutgers University Santosh Nagarakatte 114 swap Finish #1 movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset swap ’s Stack Old %ebx %esp -4 Observation n Saved & restored register %ebx yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset Old %ebx %esp -4
Image of page 114
swap Finish #2 movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset swap ’s Stack Old %ebx %esp -4 yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset swap ’s Stack %esp
Image of page 115
swap Finish #3 movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret yp xp Rtn adr %ebp 4 8 12 Offset swap ’s Stack yp xp Rtn adr Old %ebp %ebp 0 4 8 12 Offset swap ’s Stack %esp %esp
Image of page 116
Rutgers University Santosh Nagarakatte 117 swap Finish #4 movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret &zip2 &zip1 %esp Exiting Stack %ebp Observation n Saved & restored register %ebx n Didn’t do so for %eax , %ecx , or %edx yp xp Rtn adr %ebp 4 8 12 Offset swap ’s Stack %esp
Image of page 117
Rutgers University Santosh Nagarakatte 118 Register Saving Conventions When procedure yoo calls who : n yoo is the caller , who is the callee Can Register be Used for Temporary Storage?
Image of page 118
Image of page 119

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture