Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- .text
- .globl _fibofac
- _fibofac:
- pushl %ebp
- movl %esp, %ebp
- movl 8(%ebp),%eax # Moving the first parameter into eax
- pushl %eax # First argument is pushed onto stack to be argument for fac
- call _fac
- addl $4, %esp # Remove foo's argument from stack
- subl $4, %esp
- movl %eax, -4(%ebp) # Store result of fac somewhere else so %eax can be used by fib
- movl 12(%ebp),%eax
- pushl %eax
- call _fib
- addl $4, %esp # Remove fib's argument from stack
- addl -4(%ebp), %eax
- addl $4, %esp
- popl %ebp
- ret
- _fac:
- pushl %ebp
- movl %esp,%ebp
- cmpl $4, 8(%ebp) # Compare n to 4
- jle DONE # Leave because we're only dealing with n>4
- movl 8(%ebp), %eax
- subl $2, %eax # Subtract 2 because first argument for fibofac is (n-2)
- pushl %eax # Put n-2 in register and push on stack
- addl $1, %eax # Add one to create another parameter for (n-1), or ((n-2)+1)
- pushl %eax # Push (n-1) argument on stack
- call _fibofac
- addl $8, %esp # Remove arguments from stack
- imul 8(%ebp), %eax # Multiply n by result of fibofac, return that
- popl %ebp
- ret
- _fib:
- pushl %ebp
- movl %esp,%ebp
- cmpl $4, 8(%ebp)
- jle DONE
- movl 8(%ebp), %eax # Put parameter n in register
- subl $4, %eax # Subtract 4 from n to create (n-4) argument for 2nd fibofac call
- pushl %eax # Push (n-4) onto stack
- addl $1, %eax # ((n-4)+1) -> (n-3)
- pushl %eax
- call _fibofac
- addl $8, %esp
- subl $4, %esp
- movl %eax, -4(%ebp)
- #
- movl 8(%ebp), %eax
- subl $2, %eax
- pushl %eax
- addl $1, %eax
- pushl %eax
- call _fibofac
- addl $8, %esp
- #
- addl -4(%ebp),%eax
- addl $4, %esp
- popl %ebp
- ret
- DONE:
- movl $1, %eax
- popl %ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement