Skip to content

Instantly share code, notes, and snippets.

@seisvelas
Created November 29, 2018 22:18
Show Gist options
  • Select an option

  • Save seisvelas/bb2f087eb1464c926476ed5deb738879 to your computer and use it in GitHub Desktop.

Select an option

Save seisvelas/bb2f087eb1464c926476ed5deb738879 to your computer and use it in GitHub Desktop.
.section .text
.globl _start
_start:
movl $5, %edi # number of fibnum we hunt
movl $0, %ebx # 1st fibnum
movl $1, %eax # 2nd fibnum
start_loop:
## Check if %edi is 0
## (thus meaning %ebx is nth fibnum)
## and if so, exit loop
decl %edi
cmpl $0, %edi
je loop_exit
## core Fibonnaci algorithm
## (hold %eax in tmp register %edx,
## eax = eax + ebx,
## ebx = edx)
movl %eax, %edx
addl %ebx, %eax
movl %edx, %ebx
## Once loop completes...
loop_exit:
movl $1, %eax
int $0x80
@seisvelas
Copy link
Author

In the unlikely event that someone ever looks like this and wonders why it doesn't work: I forgot to add a jmp to go back to the top of the loop, so it just ran my fibonacci algorithm once and keeps running right through. See my next gist for working version of same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment