3 the effect of a call instruction is to push a

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: he compiler can assume that nmi is nonnegative. As a result, it can test the loop condition as nmi != 0 rather than nmi >= 0. This saves one instruction in the assembly code. Practice Problem 3.11: For the following C code: 1 2 3 4 5 6 7 8 9 10 11 int loop_while(int a, int b) { int i = 0; int result = a; while (i < 256) { result += a; a -= b; i += b; } return result; } generates the following assembly code: Initially a and b are at offsets 8 and 12 from %ebp GCC 1 2 3 4 5 6 7 8 9 10 11 movl 8(%ebp),%eax movl 12(%ebp),%ebx xorl %ecx,%ecx movl %eax,%edx .p2align 4,,7 .L5: addl %eax,%edx subl %ebx,%eax addl %ebx,%ecx cmpl $255,%ecx jle .L5 A. Make a table of register usage within the loop body, similar to the one shown in Figure 3.13(c). B. Identify test-expr and body-statement in the C code, and the corresponding lines in the assembly code. What optimizations has the C compiler performed on the initial test? C. Add annotations to the assembly code describing the operation of the program, similar to those shown in...
View Full Document

Ask a homework question - tutors are online