Files
equi/examples/fizzbuzz.equi

56 lines
1.5 KiB
Plaintext

(Classical FizzBuzz in Equi because why not)
(by Luxferre, 2022, public domain)
nl: 000A#D..; (define a word to output a newline)
d: 0030+.; (define a word to output a dec digit)
(I want capital letters to output properly so defining words to output Fizz and Buzz)
fizz: 0046.izz"...;
buzz: 0042.uzz"...;
(routine to output a decimal byte-sized integer without leading zeroes)
pdb: ( val -- )
0064 /%$ ( rem div div -- )
3I ( rem div -- jump 3 instructions forward if div > 0 )
!5J ( drop and jump 5 instructions forward otherwise )
d' ( rem -- output the digit )
1GS ( store flag 1 at general area )
000A /%$ ( rem div div -- )
3I ( rem div -- jump 2 instructions forward if div > 0 )
!7J ( drop and jump 7 instructions forward otherwise )
d' ( rem -- output the digit )
1GS ( store flag 1 at general area )
8J ( jump 8 instructions forward, to the remaining digit )
GL ( rem div flag -- load the flag from the general area )
2I ( rem div -- jump if flag set )
2J ( rem div -- jump over the output )
d' ( rem -- output the zero digit)
d' ( -- output the remaining digit )
;
(now, the main FizzBuzz code)
0001# ( c -- )
(loop start)
0G2+S (reset flag)
(try dividing by 3)
$3/%! ( c rem -- )
AI ( c -- )
fizz'
1G2+S (set flag)
(try dividing by 5)
$5/%! ( c rem -- )
AI ( c -- )
buzz'
1G2+S (set flag)
G2+L (load flag)
5I (skip the print if fizz or buzz)
$pdb' (print the number if neither)
nl'
0001+ ( c -- )
$ 65< ( c [c<101] -- )
42N I (jump 66 instructions backwards if the counter is less than 101)
Q