Last active
April 30, 2016 15:51
-
-
Save 1995eaton/810d953433497e130ec7 to your computer and use it in GitHub Desktop.
Fibonacci sequence in GCC assembly
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
.intel_syntax noprefix | |
.globl fib | |
fib: | |
sub rsp, 24 | |
xor eax, eax | |
mov ecx, 1 | |
0: | |
xadd rax, rcx | |
mov [rsp + 16], rax | |
mov [rsp + 8], rdi | |
mov [rsp], rcx | |
mov rsi, rax | |
lea rdi, print_fmt | |
xor eax, eax | |
call printf | |
mov rax, [rsp + 16] | |
mov rdi, [rsp + 8] | |
mov rcx, [rsp] | |
dec rdi | |
jnz 0b | |
add rsp, 24 | |
ret | |
.globl main | |
main: | |
mov edi, 70 | |
call fib | |
xor eax, eax | |
ret | |
.section .rodata | |
print_fmt: .asciz "%lu\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment