To store into eld j the code adds offset 4 to the

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: ile (x <= xend); return val; } code/asm/decimal5.c (a) Original C code (b) Equivalent pointer code Body code 1 2 3 4 5 6 7 8 9 10 movl 8(%ebp),%ecx xorl %eax,%eax leal 16(%ecx),%ebx .L12: leal (%eax,%eax,4),%edx movl (%ecx),%eax leal (%eax,%edx,2),%eax addl $4,%ecx cmpl %ebx,%ecx jbe .L12 Get base addr of array x val = 0; xend = x+4 (16 bytes = 4 double words) loop: Compute 5*val Compute *x Compute *x + 2*(5*val) x++ Compare x:xend if <=, goto loop: (c) Corresponding assembly code. Figure 3.22: C and Assembly Code for Array Loop Example. The compiler generates code similar to the pointer code shown in decimal5 opt. 3.8. ARRAY ALLOCATION AND ACCESS 147 Data type row3_t is defined to be an array of three integers. Array A contains four such elements, each requiring 12 bytes to store the three integers. The total array size is then ¡ ¡ ¿ bytes. Array A can also be viewed as a two-dimensional array with four rows and three columns, referenced as A[0][0] through A[3][2]. The array elements are orde...
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