Machine level representation of c programs struct

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: actice Problem 3.18: Suppose the address of short integer array S and integer index i are stored in registers %edx and %ecx, respectively. For each of the following expressions, give its type, a formula for its value, and an assembly code implementation. The result should be stored in register %eax if it a pointer and register element %ax if it is a short integer. Expression S+1 S[3] &S[i] S[4*i+1] S+i-5 Type Value Assembly Code 145 3.8.3 Arrays and Loops Array references within loops often have very regular patterns that can be exploited by an optimizing compiler. For example, the function decimal5 shown in Figure 3.22(a) computes the integer represented by an array of 5 decimal digits. In converting this to assembly code, the compiler generates code similar to that shown in Figure 3.22(b) as C function decimal5_opt. First, rather than using a loop index i, it uses pointer arithmetic to step through successive array elements. It computes the address of the final array element and uses a comparison to this address as the loop test. Finally, it can use a do-while loop since there will be at least one loop iteration. The assembly code shown in Figure 3.22(c) shows a further optimization to avoid the use of an integer multiply instruction. In particular, it...
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