Stack operations %eax 0x123 %edx0×123 %es90×104 opl g %edx oesp 0x108 0x1040×123 Stack“top
11 Stack operations %eax 0x123 %edx 0x123 %esp 0x104 0x104 Stack “top” 0x123 %esp 0x108 popl %edx
Data Movement Example P141 int exchange(int*xp, int y) intx=*xp /*operator* performs dereferencing*/ xp-y, returnx? int a=4 int b= exchange(&a, 3);/*address of'operatorcreates a pointer printf(“a=%d,b=%dn”,a,b); 12
12 Data Movement Example P141 int exchange(int *xp, int y) { int x = *xp ; /* operator * performs dereferencing */ *xp = y ; return x ; } int a = 4 ; int b = exchange(&a, 3); /* “address of” operator creates a pointer */ printf(“a = %d, b = %d\n”, a, b);
Data Movement Example P142 int exchange(int *xp, int I pushl %ebp 2 movl %esp, %ebp intx=*xp 3 movl 8(%ebp), %eax 4 movl 12(%ebp), %edx xp=y, 5 movl %eax), %ocx return x 6 movl %edx, (%eax) 7 movl %ecx. % oeax 8 movl %ebp, %esp 9 popl D/oebp Assembly code
13 Data Movement Example P142 int exchange(int *xp, int y) { int x = *xp ; *xp = y ; return x ; } 1 pushl %ebp 2 movl %esp, %ebp 3 movl 8(%ebp), %eax 4 movl 12(%ebp), %edx 5 movl (%eax), %ecx 6 movl %edx, (%eax) 7 movl %ecx, %eax 8 movl %ebp, %esp 9 popl %ebp Assembly code
Data Movement Example Stack Offset Y xp Rtn adr gesp
14 Data Movement Example y xp Rtn adr %esp Offset Stack • • •
Data Movement Example I pushl %ebp Stack Stack Offset Offset Y Y Rtn adr gesp 4 Rtn adr o lold %ebp 号esp 15
15 Data Movement Example y xp Rtn adr Old %ebp 0 %esp 4 8 12 Offset Stack • • • 1 pushl %ebp y xp Rtn adr %esp Offset Stack • • •