Created
November 29, 2018 22:18
-
-
Save seisvelas/bb2f087eb1464c926476ed5deb738879 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| .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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.