Last active
August 29, 2015 13:57
-
-
Save scaryghost/9750926 to your computer and use it in GitHub Desktop.
fibanocci in x86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compile: gcc -o fib fib.s -m32 | |
# run: ./fib <number> | |
.global main | |
.data | |
formatstr: .asciz "fib(%d)= %d\n" | |
main: | |
pop %ecx | |
movl 4(%eax),%edx | |
pushl %edx | |
call atoi | |
push %eax | |
movl %eax,%edi | |
call fib | |
pushl %eax | |
pushl %edi | |
pushl $formatstr | |
call printf | |
call exit | |
fib: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $4,%esp | |
movl 8(%ebp),%edx | |
cmpl $1,%edx | |
je fib_base | |
cmpl $0,%edx | |
je fib_base | |
decl %edx | |
push %edx | |
call fib | |
movl %eax,-4(%ebp) | |
pop %edx | |
decl %edx | |
push %edx | |
call fib | |
addl -4(%ebp),%eax | |
leave | |
ret | |
fib_base: | |
movl $1,%eax | |
leave | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment