Note that this form of goto is not legal c

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: 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 defined by the recurrence: ½ ¾ Ò ½ ½ Ò ¾ · Ò ¿ Ò ¿ For example, the first 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

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