diff --git a/README.md b/README.md index a32b42c..675f20b 100644 --- a/README.md +++ b/README.md @@ -243,11 +243,13 @@ representation: Examples -------- The [examples](examples/) subdirectory contains several MU8A source code file -examples for mu808 which are ports of the same 808UL example programs, namely: +examples for mu808 (some of which are ports of the same 808UL example programs), +namely: * [Compound interest calculator](examples/compound.mu8a), * [Linear regression calculator](examples/linreg.mu8a), * [Hellorld!](examples/hellorld.mu8a) (a tribute to @UsagiElectric), +* [FizzBuzz classic program](examples/fizzbuzz.mu8a), * [Bulls and Cows game](examples/moo.mu8a), * [Lunar Lander game](examples/lunar.mu8a). diff --git a/examples/fizzbuzz.mu8a b/examples/fizzbuzz.mu8a new file mode 100644 index 0000000..c13c65e --- /dev/null +++ b/examples/fizzbuzz.mu8a @@ -0,0 +1,35 @@ +; FizzBuzz classical challenge in MU8A for mu808 VM +; Outputs first 100 FizzBuzz numbers +; Created by Luxferre in 2025, released into public domain + +set 1 0 50 ; store constant 1 into loc 50 +set 100 0 51 ; store constant 100 into loc 51 +set 3 0 3 ; store constant 3 into loc 3 +set 5 0 5 ; store constant 5 into loc 5 +set 70 0 60 ; store Fi into loc 60-61 +set 105 0 61 +set 66 0 62 ; store Buz + LF into loc 62-65 +set 117 0 63 +set 122 0 64 +set 10 0 65 +set 1 0 1 ; counter in loc 1 +:lp mdf 1 3 2 ; loop start; store counter mod 3 into loc 2 +mdf 1 5 4 ; store counter mod 5 into loc 4 +set 1 0 10 ; set normal output flag to loc 10 +jmp 5 2 :bu ; jump next if not divisible by 3 +out 60 61 1 ; output Fizz sequence +out 64 64 1 +out 64 64 1 +set 0 0 10 ; unset normal output flag +:bu jmp 5 4 :no ; jump next if not divisible by 5 +out 62 63 1 ; output Buzz sequence +out 64 64 1 +out 64 64 1 +set 0 0 10 ; unset normal output flag +:no jmp 0 10 :n ; jump next if normal output flag is off +out 1 1 0 ; normal counter output +jmp 6 0 :le ; jump to the end of the loop +:n out 65 65 1 ; output a newline +:le fma 50 50 1 ; increment the counter +sub 1 51 6 ; save the difference into loc 6 +jmp 4 6 :lp ; go back in the loop if not every number is displayed yet