150 3 4 5 6 7 8 chapter 3 machine level

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: bytes Save %esi (offset Save %ebx (offset pointer on stack -20) -24) 7 8 9 10 11 12 13 14 15 16 17 18 19 20 movl 8(%ebp),%ebx cmpl $2,%ebx jle .L24 addl $-12,%esp leal -2(%ebx),%eax pushl %eax call fib_rec movl %eax,%esi addl $-12,%esp leal -1(%ebx),%eax pushl %eax call fib_rec addl %esi,%eax jmp .L25 Terminal condition Get n Compare n:2 if <=, goto terminate Allocate 12 bytes on stack Compute n-2 Push as argument Call fib_rec(n-2) Store result in %esi Allocate 12 bytes to stack Compute n-1 Push as argument Call fib_rec(n-1) Compute val+nval Go to done 21 22 .L24: movl $1,%eax Finishing code terminate: Return value 1 23 24 25 26 27 28 29 .L25: leal popl popl movl popl ret done: -24(%ebp),%esp %ebx %esi %ebp,%esp %ebp Set stack to offset -24 Restore %ebx Restore %esi Restore stack pointer Restore %ebp Return Figure 3.20: Assembly Code for the Recursive Fibonacci Program in Figure 3.19. 142 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS • • • +8 +4 %ebp 0 n Return Address Sa...
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