This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ody-statement t = test-expr; if (t) goto loop; As an example, Figure 3.12 shows an implementation of a routine to compute the Òth element in the Fibonacci sequence using a do-while loop. This sequence is deﬁned by the recurrence:
Ò ½ ½
Ò ¾ · Ò ¿ Ò ¿ For example, the ﬁrst ten elements of the sequence are 1, 1, 2, 3, 5, 8, 13, 21, 34, and 55. To implement this using a do-while loop, we have started the sequence with values ¼ ¼ and ½ ½, rather than with ½ and ¾ . The assembly code implementing the loop is also shown, along with a table showing the correspondence between registers and program values. In this example, body-statement consists of lines 8 through 11, assigning values to t, val, and nval, along with the incrementing of i. These are implemented by lines 2 through 5 of the assembly code. The expression i < n comprises test-expr. This is implemented by line 6 and by the test condition of the jump instruction on line 7. Once the loop exits, val is copy to register %eax as the return value (li...
View Full Document
- Spring '10
- The American