End aside 136 chapter 3 machine level representation

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: L6 .L4: was generated by compiling C code that had the following overall form 1 2 3 4 5 6 7 8 9 int loop(int x, int y, int n) { int result = 0; int i; for (i = ____; i ____ ; i = ___ ) { result += _____ ; } return result; } Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. Recall that the result of the function is returned in register %eax. To solve this problem, you may need to do a little bit of guessing about register usage and then see whether that guess makes sense. A. Which registers hold program values result and i? B. What is the initial value of i? C. What is the test condition on i? D. How does i get updated? E. The C expression describing how to increment result in the loop body does not change value from one iteration of the loop to the next. The compiler detected this and moved its computation to before the loop. What is the expression? F. Fill in all the missing parts of the C code. 3.6.6 Switch Statements Switch statements provide a multi-way branching capability based on the value of an integer index. They are particularly useful when dealing with tests where there can be a large number of possible outcomes. Not only do they make the C code more readable, they also allow an efficient implementation using a data structure called a jump table....
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