Created
October 26, 2019 23:23
-
-
Save wmmnola/e944c70b160c8a27d5087c093489852d to your computer and use it in GitHub Desktop.
AT&T Assembly implementation of Fizzbuzz
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
.fizz : .string "Fizz" | |
.buzz : .string "Buzz" | |
.endline : .string ":%d \n" | |
.global main | |
.newline: | |
push %rdi | |
push %rsi | |
mov $.endline, %rdi | |
mov %r8, %rsi | |
xor %rax, %rax | |
call printf | |
pop %rdi | |
pop %rsi | |
jmp _fizzbuzz | |
.printfizz: | |
push %rdi | |
push %rsi | |
mov $.fizz, %rdi | |
xor %rax, %rax | |
call printf | |
pop %rsi | |
pop %rdi | |
ret | |
.printbuzz: | |
push %rdi | |
push %rsi | |
mov $.buzz, %rdi | |
xor %rax, %rax | |
call printf | |
pop %rsi | |
pop %rdi | |
ret | |
.checkThree: # Store what to divide in %rdi | |
xor %rdx, %rdx | |
mov %rdi, %rax | |
mov $3, %rbx | |
idiv %rbx | |
cmp $0, %rdx | |
je .printfizz | |
ret | |
.checkFive: #Store what to divide in %rdi | |
xor %rdx, %rdx | |
mov %rdi, %rax | |
mov $5, %rbx | |
idiv %rbx | |
cmp $0, %rdx | |
je .printbuzz | |
ret | |
fizzbuzz: # maximum value in %rdi | |
mov $0, %r8 | |
mov $5, %r10 | |
push %r8 | |
_fizzbuzz: | |
pop %r8 | |
inc %r8 | |
push %rdi | |
mov %r8, %rdi | |
call .checkThree | |
call .checkFive | |
pop %rdi | |
cmp %r8, %rdi | |
push %r8 | |
jge .newline | |
pop %r8 | |
ret | |
main: | |
mov $30, %rdi | |
call fizzbuzz | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment