1 int mat1mn 148 2 3 4 5 6 7 chapter 3 machine level

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: m %eax to a different register. Practice Problem 3.16: Given the following C function: 1 2 3 4 5 6 int proc(void) { int x,y; scanf("%x %x", &y, &x); return x-y; } generates the following assembly code proc: pushl %ebp movl %esp,%ebp subl $24,%esp addl $-4,%esp leal -4(%ebp),%eax pushl %eax leal -8(%ebp),%eax pushl %eax pushl $.LC0 Pointer to string "%x %x" call scanf Diagram stack frame at this point GCC 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 movl movl subl movl movl popl ret -8(%ebp),%eax -4(%ebp),%edx %eax,%edx %edx,%eax %ebp,%esp %ebp Assume that procedure proc starts executing with the following register values: Register %esp %ebp Value 0x800040 0x800060 140 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/fib.c 1 2 3 4 5 6 7 8 9 10 int fib_rec(int n) { int prev_val, val; if (n <= 2) return 1; prev_val = fib_rec(n-2); val = fib_rec(n-1); return prev_val + val; } code/asm/fib.c Figure 3.19: C Code for Recursive Fibonacci Program. Suppose proc calls scanf...
View Full Document

Ask a homework question - tutors are online