Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.