%define COUNT 20
[bits 16]
[org 0x7c00]
start:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov ax, 0x9c00
mov sp, ax
mov cx, COUNT
sti
fizzbuzz:
.printnumber:
mov ax, cx
call putword
.test3:
mov ax, cx
mov dh, 3
div dh
or ah, ah
jz .fizz
.test5:
mov ax, cx
mov dh, 5
div dh
or ah, ah
jz .buzz
jmp .testcx
.fizz:
mov si, fizz
call putstr
jmp .test5
.buzz:
mov si, buzz
call putstr
.testcx:
mov si, crlf
call putstr
or cx, cx
jz hang
dec cx
jmp fizzbuzz
hang:
cli
hlt
jmp $
putchar:
mov ah, 0x0e
int 0x10
ret
putstr:
.do_char:
lodsb
or al, al
jz .done
call putchar
jmp .do_char
.done:
ret
putnibble:
cmp al, 10
jl .lt10
add al, 'A' - 10
call putchar
jmp .done
.lt10:
add al,'0'
call putchar
.done:
ret
putbyte:
push ax
shr al, 4
call putnibble
pop ax
and al, 0x0f
call putnibble
cmp bx, 0
je .done
mov al, ' '
call putchar
.done:
ret
putword:
push bx
push ax
mov al, ah
mov bx, 0
call putbyte
pop ax
mov bx, 0
call putbyte
mov al, ' '
call putchar
pop bx
ret
fizz: db "fizz", 0
buzz: db "buzz", 0
crlf: db 13, 10, 0
times 510 - ($ - $$) db 0
dw 0xaa55
JWRlZmluZSBDT1VOVCAgICAyMApbYml0cyAxNl0KW29yZyAgMHg3YzAwXQpzdGFydDoKICAgIGNsaQogICAgeG9yIGF4LCBheAogICAgbW92IGRzLCBheAogICAgbW92IGVzLCBheAogICAgbW92IHNzLCBheAogICAgbW92IGF4LCAweDljMDAKICAgIG1vdiBzcCwgYXgKICAgIG1vdiBjeCwgQ09VTlQKICAgIHN0aQpmaXp6YnV6ejoKICAgIC5wcmludG51bWJlcjoKICAgICAgICBtb3YgIGF4LCBjeAogICAgICAgIGNhbGwgcHV0d29yZAogICAgLnRlc3QzOgogICAgICAgIG1vdiBheCwgY3gKICAgICAgICBtb3YgZGgsIDMKICAgICAgICBkaXYgZGgKICAgICAgICBvciAgYWgsIGFoCiAgICAgICAganogIC5maXp6CiAgICAudGVzdDU6CiAgICAgICAgbW92IGF4LCBjeAogICAgICAgIG1vdiBkaCwgNQogICAgICAgIGRpdiBkaAogICAgICAgIG9yICBhaCwgYWgKICAgICAgICBqeiAgLmJ1enoKICAgICAgICBqbXAgLnRlc3RjeAogICAgLmZpeno6CiAgICAgICAgbW92ICBzaSwgZml6egogICAgICAgIGNhbGwgcHV0c3RyCiAgICAgICAgam1wICAudGVzdDUKICAgIC5idXp6OgogICAgICAgIG1vdiAgc2ksIGJ1enoKICAgICAgICBjYWxsIHB1dHN0cgogICAgLnRlc3RjeDoKICAgICAgICBtb3YgIHNpLCBjcmxmCiAgICAgICAgY2FsbCBwdXRzdHIKICAgICAgICBvciAgIGN4LCBjeAogICAgICAgIGp6ICAgaGFuZwogICAgICAgIGRlYyAgY3gKICAgICAgICBqbXAgIGZpenpidXp6Cmhhbmc6CiAgICBjbGkKICAgIGhsdAogICAgam1wICQKcHV0Y2hhcjoKICAgIG1vdiBhaCwgMHgwZQogICAgaW50IDB4MTAKICAgIHJldApwdXRzdHI6CiAgICAuZG9fY2hhcjoKICAgICAgICBsb2RzYgogICAgICAgIG9yICAgYWwsIGFsCiAgICAgICAganogICAuZG9uZQogICAgICAgIGNhbGwgcHV0Y2hhcgogICAgICAgIGptcCAgLmRvX2NoYXIKICAgIC5kb25lOgogICAgICAgIHJldApwdXRuaWJibGU6CiAgICBjbXAgIGFsLCAxMAogICAgamwgICAubHQxMAogICAgYWRkICBhbCwgJ0EnIC0gMTAKICAgIGNhbGwgcHV0Y2hhcgogICAgam1wICAuZG9uZQogICAgLmx0MTA6CiAgICAgICAgYWRkICBhbCwnMCcKICAgICAgICBjYWxsIHB1dGNoYXIKICAgIC5kb25lOgogICAgICAgIHJldApwdXRieXRlOgogICAgcHVzaCBheAogICAgc2hyICBhbCwgNAogICAgY2FsbCBwdXRuaWJibGUKICAgIHBvcCAgYXgKICAgIGFuZCAgYWwsIDB4MGYKICAgIGNhbGwgcHV0bmliYmxlCiAgICBjbXAgIGJ4LCAwCiAgICBqZSAgIC5kb25lCiAgICBtb3YgIGFsLCAnICcKICAgIGNhbGwgcHV0Y2hhcgogICAgLmRvbmU6CiAgICAgICAgcmV0CnB1dHdvcmQ6CiAgICBwdXNoIGJ4CiAgICBwdXNoIGF4CiAgICBtb3YgIGFsLCBhaAogICAgbW92ICBieCwgMAogICAgY2FsbCBwdXRieXRlCiAgICBwb3AgIGF4CiAgICBtb3YgIGJ4LCAwCiAgICBjYWxsIHB1dGJ5dGUKICAgIG1vdiAgYWwsICcgJwogICAgY2FsbCBwdXRjaGFyCiAgICBwb3AgIGJ4CiAgICByZXQKZml6ejogICAgICAgICAgICAgICAgZGIgImZpenoiLCAwCmJ1eno6ICAgICAgICAgICAgICAgIGRiICJidXp6IiwgMApjcmxmOiAgICAgICAgICAgICAgICBkYiAxMywgMTAsIDAKdGltZXMgNTEwIC0gKCQgLSAkJCkgZGIgMAogICAgICAgICAgICAgICAgICAgICBkdyAweGFhNTUK