Skip to content

Instantly share code, notes, and snippets.

@marnixk
Created April 2, 2025 04:28
Show Gist options
  • Save marnixk/50be99ff1674c98d2e5e6fd6a841521e to your computer and use it in GitHub Desktop.
Save marnixk/50be99ff1674c98d2e5e6fd6a841521e to your computer and use it in GitHub Desktop.
Small Fizzbuzz
.model tiny
.code
org 0100h
start:
; initialise counters
mov cl, 0
restart:
mov si, offset circ
next_number:
; load next relative pointer from [circ] into AL
xor ax, ax
lodsb
; before doing any printing, let's update the values in [number]
adjust_number:
mov di, offset number
; add "offset number" to ax to point di to start of string
add ax, di
; DX = AX (used for printing later)
mov dx, ax
; increase because we're 1-based not 0-based
inc cx
two_digits:
; first digit
mov ax, cx
mov bl, 10
div bl
add ax, 3030h
; first byte is '0'? replace with 'return'
cmp al, 30h
jne store_now
mov al, 13
store_now:
stosw
; k, let's print whatever we're pointing at.
start_printing:
mov ax, 0924h
int 21h
mov dx, offset newline
int 21h
cmp cl, 20
je done
cmp si, offset circ + 15
je restart
jmp next_number
done:
ret
; ____ _
; | _ \ __ _| |_ __ _
; | | | |/ _` | __/ _` |
; | |_| | (_| | || (_| |
; |____/ \__,_|\__\__,_|
;
; relative offsets of strings we can print
number_start EQU 0
fizz_start EQU 3
buzz_start EQU 8
fizzbuzz_start EQU 13
number db ' $'
fizz db 'Fizz$'
buzz db 'Buzz$'
fizzbuzz db 'FizzBuzz$'
newline db 13, 10, '$'
; pattern of finding fizzbuzz combinations
circ:
db number_start, number_start, fizz_start, number_start, buzz_start
db fizz_start, number_start, number_start, fizz_start, buzz_start, number_start
db fizz_start, number_start, number_start, fizzbuzz_start
END start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment