Last active
August 29, 2015 14:24
-
-
Save badcc/0df09e597f016f875f80 to your computer and use it in GitHub Desktop.
Asm x86-64 Fibonacci Sequence Generator with Command Line Input
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 # Set dialect to Intel (AT&T default for GAS) | |
.global main | |
.format: | |
.asciz "%2d\n" | |
main: | |
mov rdi, [rsi + 8] # argv[1] | |
call atoi # > eax | |
mov ecx, eax # Number of calculations / output | |
push rbx | |
xor rax, rax # Set current equal to 0 | |
xor rbx, rbx # Set next equal to 0 | |
inc rbx | |
print: | |
mov rdi, OFFSET FLAT:.format # First parameter | |
mov rsi, rax # Second parameter | |
push rax # Save ax | |
push rcx # Save cx | |
call printf | |
pop rcx # Load ax | |
pop rax # Load cx | |
mov rdx, rax | |
mov rax, rbx | |
add rbx, rdx | |
dec ecx | |
jnz print | |
pop rbx | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment