Skip to content

Instantly share code, notes, and snippets.

@auxiliary-character
Last active September 22, 2018 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auxiliary-character/4e89ea4b0ece82e551f9c9ff19356fbe to your computer and use it in GitHub Desktop.
Save auxiliary-character/4e89ea4b0ece82e551f9c9ff19356fbe to your computer and use it in GitHub Desktop.
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