On the other hand registers ebx esi and edi are

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: done: This, in turn, can be transformed into goto code as: 3.6. CONTROL init-expr; t = test-expr; if (!t) goto done; loop: body-statement update-expr; t = test-expr; if (t) goto loop; done: 127 As an example, the following code shows an implementation of the Fibonacci function using a for loop: code/asm/fib.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 int fib_f(int n) { int i; int val = 1; int nval = 1; for (i = 1; i < n; i++) { int t = val+nval; val = nval; nval = t; } return val; } code/asm/fib.c The transformation of this code into the while loop form gives code identical to that for the function fib_w shown in Figure 3.13. In fact, GCC generates identical assembly code for the two functions. Practice Problem 3.12: The following assembly code: Initially x, y, and n are offsets 8, 12, and 16 from %ebp 1 2 3 4 5 6 movl 8(%ebp),%ebx movl 16(%ebp),%edx xorl %eax,%eax decl %edx js .L4 movl %ebx,%ecx 128 7 8 9 10 11 12 13 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS imull 12(%ebp),%ecx .p2align 4,,7 Inserted to optimize cache performance .L6: addl %ecx,%eax subl %ebx,%edx jns ....
View Full Document

Ask a homework question - tutors are online