In c we would simply write these as ordinary

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: uses leal (line 5) to compute 5*val as val+4*val. It then uses leal with a scaling factor of 2 (line 7) to scale to 10*val. Aside: Why avoid integer multiply? In older models of the IA32 processor, the integer multiply instruction took as many as 30 clock cycles, and so compilers try to avoid it whenever possible. In the most recent models it requires only 3 clock cycles, and therefore these optimizations are not warranted. End Aside. 3.8.4 Nested Arrays The general principles of array allocation and referencing hold even when we create arrays of arrays. For example, the declaration: int A[4][3]; is equivalent to the declaration: typedef int row3_t[3]; row3_t A[4]; 146 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/decimal5.c 1 2 3 4 5 6 7 8 9 10 code/asm/decimal5.c 1 2 3 4 5 6 7 8 9 10 11 12 int decimal5(int *x) { int i; int val = 0; for (i = 0; i < 5; i++) val = (10 * val) + x[i]; return val; } code/asm/decimal5.c int decimal5_opt(int *x) { int val = 0; int *xend = x + 4; do { val = (10 * val) + *x; x++; } wh...
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