sectorforth/examples/05-fizzbuzz.f
2020-09-26 22:20:15 -07:00

22 lines
558 B
Forth

\ FizzBuzz example for sectorforth, a 512-byte, bootable x86 Forth.
\ Copyright (c) 2020 Cesar Blum
\ Distributed under the MIT license. See LICENSE for details.
\ Depends on definitions built up to the stack debugging example.
\ get do...loop index
: i ( -- index ) rp@ 4 + @ ;
\ make more numbers
: 3 1 2 + ;
: 5 2 3 + ;
\ newline
: cr lit [ 4 6 3 + + , ] lit [ 4 6 + , ] emit emit ;
: fizzbuzz ( x -- )
cr 1 + 1 do
i 3 mod 0= dup if ." Fizz" then
i 5 mod 0= dup if ." Buzz" then
or invert if i . then
cr
loop ;