Last active
September 22, 2018 18:40
-
-
Save auxiliary-character/4e89ea4b0ece82e551f9c9ff19356fbe to your computer and use it in GitHub Desktop.
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
global main | |
extern puts | |
extern sprintf | |
section .text | |
main: | |
push rbx | |
mov r15, 100 | |
mov r14, 1 | |
loop: | |
;print the loop variable into the buffer | |
mov rdi, buffer | |
mov rsi, format | |
mov rdx, r14 | |
call sprintf | |
;modulo 3 check | |
mov rax, r14 | |
mov rbx, 3 | |
xor rdx, rdx | |
div rbx | |
test rdx, rdx | |
setz al | |
shl al, 1 | |
mov r8, rax | |
;modulo 5 check | |
mov rax, r14 | |
mov rbx, 5 | |
xor rdx, rdx | |
div rbx | |
test rdx, rdx | |
setz dl | |
or rdx, r8 | |
;index array of string pointers, and print | |
mov rdi, [arr + rdx*8] | |
call puts | |
;increment, loop, and return if finished | |
inc r14 | |
cmp r14, r15 | |
jne loop | |
pop rbx | |
ret | |
section .data | |
format: db "%u", 0 ;format string for sprintf call | |
buzz: db "Buzz", 0 | |
fizz: db "Fizz", 0 | |
fizzbuzz: db "Fizzbuzz", 0 | |
;array of string pointers for indexing | |
arr: dq buffer, buzz, fizz, fizzbuzz | |
section .bss | |
buffer: resb 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment