Files
n808/examples/fizzbuzz.n8a
T

40 lines
1.5 KiB
Plaintext
Raw Normal View History

2025-05-04 11:46:54 +03:00
; FizzBuzz classical challenge in N8A for n808 VM
; Outputs first 100 FizzBuzz numbers
; Created by Luxferre in 2025, released into public domain
dca 70 60 ; store Fi into loc 60-61
dca 105 61
dca 66 62 ; store Buz + LF into loc 62-65
dca 117 63
dca 122 64
dca 10 65
#1 cntr ; counter in loc 1
#2 cmod3 ; variable for counter mod 3
#3 cmod5 ; variable for counter mod 5
#4 chk ; variable for loop checks
#5 oflag ; normal output flag variable
dca 0 @cntr ; set counter to 0
:lp inc @cntr ; loop start, increment the counter
dca 3 @cmod3 ; store constant 3
mdf @cntr @cmod3 ; store counter mod 3
dca 5 @cmod5 ; store constant 5
mdf @cntr @cmod5 ; store counter mod 5
dca 1 @oflag ; set normal output flag
jne @cmod3 :bu ; jump next if not divisible by 3
ouc 60 61 ; output Fizz sequence
ouc 64 64
ouc 64 64
dca 0 @oflag ; unset normal output flag
:bu jne @cmod5 :no ; jump next if not divisible by 5
ouc 62 63 ; output Buzz sequence
ouc 64 64
ouc 64 64
dca 0 @oflag ; unset normal output flag
:no jeq @oflag :nl ; jump next if normal output flag is off
out @cntr @cntr ; normal counter output
juc :le ; jump to the end of the loop
:nl ouc 65 65 ; output a newline
:le dca 100 @chk ; store the constant 100 into checkvar
sub @cntr @chk ; save the difference into checkvar
jlt @chk :lp ; go back in the loop if not every number is displayed yet