324_Book

# Machine level representation of c programs where the

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ¡½ . Finally, the code can use a simple counter to keep track of the number of iterations required. We have shown the C code fix_prod_ele_opt to illustrate the optimizations made by the C compiler in generating the assembly. The actual assembly code for the loop is shown below. Aptr is in %edx, Bptr in %ecx, result in %esi, cnt in %ebx loop: Compute t = *Aptr 1 2 .L23: movl (%edx),%eax 3.8. ARRAY ALLOCATION AND ACCESS 149 code/asm/array.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #define N 16 typedef int fix_matrix[N][N]; /* Compute i,k of fixed matrix product */ int fix_prod_ele (fix_matrix A, fix_matrix B, { int j; int result = 0; for (j = 0; j < N; j++) result += A[i][j] * B[j][k]; return result; } code/asm/array.c int i, int k) (a) Original C code code/asm/array.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /* Compute i,k of fixed matrix product */ int fix_prod_ele_opt(fix_matrix A, fix_matrix B, int i, int k) { int *Aptr = &A[i][0]; int *Bptr = &B[0][k]; int cnt = N - 1; int result = 0; do { result += (*Aptr) * (*Bptr); Aptr += 1; Bptr += N; cnt--; } while (cnt >= 0); return result; } c...
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