The argument will be at offset 8 relative to ebp

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: ode/asm/array.c (b) Optimized C code. Figure 3.23: Original and Optimized Code to Compute Element of Matrix Product for Fixed Length Arrays. The compiler performs these optimizations automatically. 150 3 4 5 6 7 8 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS imull (%ecx),%eax addl %eax,%esi addl $64,%ecx addl $4,%edx decl %ebx jns .L23 Compute v = *Bptr * t Add v result Add 64 to Bptr Add 4 to Aptr Decrement cnt if >=, goto loop Note that in the above code, all pointer increments are scaled by a factor of 4 relative to the C code. Practice Problem 3.20: The following C code sets the diagonal elements of a fixed-size array to val 1 2 3 4 5 6 7 /* Set all diagonal elements to val */ void fix_set_diag(fix_matrix A, int val) { int i; for (i = 0; i < N; i++) A[i][i] = val; } When compiled GCC generates the following assembly code: 1 2 3 4 5 6 7 8 9 10 movl 12(%ebp),%edx movl 8(%ebp),%eax movl $15,%ecx addl $1020,%eax .p2align 4,,7 .L50: movl %edx,(%eax) addl $-68,%eax decl %ecx jns .L50 Added to optimize cache performance Create a C code program fix_set_diag...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online