Rate my babby's first assembly fizzbuzz:
.global _start
.intel_syntax noprefix
.text
_start:
mov rbx, 1
mov rdx, 0
_start_loop:
cmp rbx, 100
jg _exit
mov rax, rbx
mov rcx, 3
cqo
div rcx
mov r8, rdx
mov rax, rbx
mov rcx, 5
cqo
div rcx
mov r9, rdx
mov r10, rdx
or r10, r8
mov rdx, 9
lea rsi, [fizzbuzz]
cmp r10, 0
je _print
mov rdx, 5
lea rsi, [fizz]
cmp r8, 0
je _print
lea rsi, [buzz]
cmp r9, 0
je _print
_print_number:
mov r8, 1
lea rsi, [number+20]
mov rax, rbx
mov rcx, 10
_print_number_loop:
cqo
div rcx
add rdx, 0x30
dec rsi
mov [rsi], dl
inc r8
test rax, rax
jz _no_more_digits
jmp _print_number_loop
_no_more_digits:
mov rdx, r8
_print:
mov rax, 1
mov rdi, 1
syscall
inc rbx
jmp _start_loop
_exit:
mov rax, 60
mov rdi, 0
syscall
fizz:
.ascii "fizz\n"
buzz:
.ascii "buzz\n"
fizzbuzz:
.ascii "fizzbuzz\n"
.data
number:
.space 21, 0x0A