324_Book

# As described earlier the stack grows toward lower

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n val; } code/asm/ﬁb.c int fib_w_goto(int n) { int val = 1; int nval = 1; int nmi, t; if (val >= n) goto done; nmi = n-1; loop: t = val+nval; val = nval; nval = t; nmi--; if (nmi) goto loop; done: return val; } code/asm/ﬁb.c 17 18 19 20 21 (a) C code. 1 2 3 4 5 6 7 8 9 10 11 12 13 (b) Equivalent goto version of (a). movl 8(%ebp),%eax movl \$1,%ebx movl \$1,%ecx cmpl %eax,%ebx jge .L9 leal -1(%eax),%edx .L10: leal (%ecx,%ebx),%eax movl %ecx,%ebx movl %eax,%ecx decl %edx jnz .L10 .L9: Get n Set val to 1 Set nval to 1 Compare val:n If >= goto done: nmi = n-1 loop: Compute t = nval+val Set val to nval Set nval to t Decrement nmi if != 0, goto loop: done: Register Usage Register Variable Initially %edx nmi n-1 %ebx val 1 %ecx nval 1 (c) Corresponding assembly language code. Figure 3.13: C and Assembly Code for While Version of Fibonacci. The compiler has performed a number of optimizations, including replacing the value denoted by variable i with one we call nmi. 3.6. CONTROL 125 successive executions of the loop we are assured that Ò, and so t...
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