Expression s1 s3 si s4i1 si 5 type value assembly

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gram then modifies these and three other registers (%eax, %ecx, and %edx). At the end of the procedure, the values of registers %edi, %esi, and %ebx are restored using popl instructions, while the other three are left in their modified states. Explain this apparently inconsistency in the saving and restoring of register states. 3.7. PROCEDURES 137 code/asm/swapadd.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 int swap_add(int *xp, int *yp) { int x = *xp; int y = *yp; *xp = y; *yp = x; return x + y; } int caller() { int arg1 = 534; int arg2 = 1057; int sum = swap_add(&arg1, &arg2); int diff = arg1 - arg2; return sum * diff; } code/asm/swapadd.c Figure 3.17: Example of Procedure Definition and Call. 3.7.4 Procedure Example As an example, consider the C procedures defined in Figure 3.17. Figure 3.18 shows the stack frames for the two procedures. Observe that swap_add retrieves its arguments from the stack frame for caller. These locations are accessed relative to the frame pointer in register %ebp. The n...
View Full Document

Ask a homework question - tutors are online