The stack is used to pass procedure arguments to

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: would be: 3.6. CONTROL loop: t = test-expr; if (!t) goto done; body-statement goto loop; done: 123 This translation requires two control statements within the inner loop—the part of the code that is executed the most. Instead, most C compilers transform the code into a do-while loop by using a conditional branch to skip the first execution of the body if needed: if (!test-expr) goto done; do body-statement while (test-expr); done: This, in turn, can be transformed into goto code as: t = test-expr; if (!t) goto done; loop: body-statement t = test-expr; if (t) goto loop; done: As an example, Figure 3.13 shows an implementation of the Fibonacci sequence function using a while loop (a). Observe that this time we have started the recursion with elements ½ (val) and ¾ (nval). The adjacent C function fib_w_goto (b) shows how this code has been translated into assembly. The assembly code in (c) closely follows the C code shown in fib_w_goto. The compiler has performed several interesting optimizations,...
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