Skip to content

Instantly share code, notes, and snippets.

@seisvelas
Created November 29, 2018 22:41
Show Gist options
  • Save seisvelas/9b9ca7d5c5962f0aed909c6d255cfcdd to your computer and use it in GitHub Desktop.
Save seisvelas/9b9ca7d5c5962f0aed909c6d255cfcdd to your computer and use it in GitHub Desktop.
Exit with status code of the nth fib number, where n is stored in %edi
.section .data
.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
jmp start_loop
## Once loop completes...
loop_exit:
movl $1, %eax
int $0x80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment