equi

A self-descriptive stack-based PC platform
git clone git://git.luxferre.top/equi.git
Log | Files | Refs | README | LICENSE

fizzbuzz.equi (1544B)


      1 (Classical FizzBuzz in Equi because why not)
      2 (by Luxferre, 2022, public domain)
      3 
      4 nl: 000A#D..; (define a word to output a newline)
      5 d: 0030+.; (define a word to output a dec digit)
      6 
      7 (I want capital letters to output properly so defining words to output Fizz and Buzz)
      8 
      9 fizz: 0046.izz"...;
     10 buzz: 0042.uzz"...;
     11 
     12 (routine to output a decimal byte-sized integer without leading zeroes)
     13 
     14 pdb: ( val -- )
     15   0064 /%$ ( rem div div -- )
     16   3I ( rem div -- jump 3 instructions forward if div > 0 )
     17   !5J ( drop and jump 5 instructions forward otherwise )
     18   d' ( rem -- output the digit )
     19   1GS ( store flag 1 at general area )
     20   000A /%$ ( rem div div -- )
     21   3I ( rem div -- jump 2 instructions forward if div > 0 )
     22   !7J ( drop and jump 7 instructions forward otherwise )
     23   d' ( rem -- output the digit )
     24   1GS ( store flag 1 at general area )
     25   8J ( jump 8 instructions forward, to the remaining digit )
     26   GL ( rem div flag -- load the flag from the general area )
     27   2I ( rem div -- jump if flag set )
     28   2J ( rem div -- jump over the output )
     29   d' ( rem -- output the zero digit)
     30   d' ( -- output the remaining digit )
     31 ;
     32 
     33 (now, the main FizzBuzz code)
     34 
     35 0001# ( c -- )
     36 (loop start)
     37 0G2+S (reset flag)
     38 (try dividing by 3)
     39 $3/%! ( c rem -- )
     40 AI ( c -- )
     41 fizz' 
     42 1G2+S (set flag)
     43 (try dividing by 5)
     44 $5/%! ( c rem -- )
     45 AI ( c -- )
     46 buzz'
     47 1G2+S (set flag)
     48 G2+L (load flag)
     49 5I (skip the print if fizz or buzz)
     50 $pdb' (print the number if neither)
     51 nl'
     52 0001+ ( c -- )
     53 $ 65< ( c [c<101] -- )
     54 42N I (jump 66 instructions backwards if the counter is less than 101)
     55 Q