This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Figure 3.13(c). D. Write a goto version (in C) of the function that has similar structure to the assembly code, as was done in Figure 3.13(b). 126 For Loops CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS The general form of a for loop is as follows: for (init-expr; test-expr; update-expr) body-statement The C language standard states that the behavior of such a loop is identical to the following code using a while loop: init-expr; while (test-expr) body-statement update-expr; That is, the program ﬁrst evaluates the initialization expression init-expr. It then enters a loop where it ﬁrst evaluates the test condition test-expr, exiting if the test fails, then executes the body of the loop bodystatement, and ﬁnally evaluates the update expression update-expr. The compiled form of this code then is based on the transformation from while to do-while described previously, ﬁrst giving a do-while form: init-expr; if (!test-expr) goto done; do body-statement update-expr; while (test-expr);...
View Full Document
- Spring '10
- The American