Skip to content

Instantly share code, notes, and snippets.

@keiya
Created September 16, 2011 23:31
Show Gist options
  • Save keiya/1223397 to your computer and use it in GitHub Desktop.
Save keiya/1223397 to your computer and use it in GitHub Desktop.
Fibonacci in Assembly
.data
.align 4
res: .long 0,0,0,0,0,0,0,0,0,0,0
.text
.globl main
main:
mov $0,%eax #; temporary
mov $0,%esi #; counter (n)
mov %eax,res(,%esi,4) #; res[n] = 0
add $1,%esi
mov $1,%eax
mov %eax,res(,%esi,4) #; res[n+1] = 1
add $1,%esi
mov $1,%edx #; %ebx = n-1
mov $0,%ecx #; %ecx = n-2
L1:
cmp $11,%esi
je L2
mov $0,%eax
add res(,%edx,4),%eax
add res(,%ecx,4),%eax
mov %eax,res(,%esi,4)
add $1,%esi
add $1,%edx
add $1,%ecx
jmp L1
L2:
mov $0,%ebx
mov res(,%edx,4),%ebx
call stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment