Skip to content

Instantly share code, notes, and snippets.

@1995eaton
Last active April 30, 2016 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1995eaton/810d953433497e130ec7 to your computer and use it in GitHub Desktop.
Save 1995eaton/810d953433497e130ec7 to your computer and use it in GitHub Desktop.
Fibonacci sequence in GCC assembly
.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