34 lines
602 B
Tal
34 lines
602 B
Tal
( FizzBuzz: From 1 to 100, for multiples of 3 print "Fizz", of 5 "Buzz" and for both "FizzBuzz" )
|
|
|
|
@on-reset ( -> )
|
|
#6400
|
|
&loop ( -- )
|
|
DUP <print-dec>
|
|
#2018 DEO
|
|
DUP #03 DIVk MUL SUB ?{ ;dict/fizz <print-str>/ }
|
|
DUP #05 DIVk MUL SUB ?{ ;dict/buzz <print-str>/ }
|
|
#0a18 DEO
|
|
INC GTHk ?&loop
|
|
POP2
|
|
( exit ) #800f DEO
|
|
BRK
|
|
|
|
@<print-dec> ( num -- )
|
|
( x0 ) DUP #0a DIV <print-num>
|
|
( 0x ) #0a DIVk MUL SUB
|
|
( >> )
|
|
|
|
@<print-num> ( num -- )
|
|
#30 ADD #18 DEO
|
|
JMP2r
|
|
|
|
@<print-str> ( addr* -- )
|
|
LDAk #18 DEO
|
|
INC2 & LDAk ?<print-str>
|
|
POP2 JMP2r
|
|
|
|
@dict ( strings )
|
|
&fizz "Fizz $1
|
|
&buzz "Buzz $1
|
|
|