2023-07-21 14:35:56 -04:00
|
|
|
( FizzBuzz: From 1 to 100, for multiples of 3 print "Fizz", of 5 "Buzz" and for both "FizzBuzz" )
|
2021-10-12 21:38:45 -04:00
|
|
|
|
2023-07-21 14:35:56 -04:00
|
|
|
|0100
|
|
|
|
|
|
|
|
@on-reset ( -> )
|
2021-10-12 21:38:45 -04:00
|
|
|
#6400
|
2023-07-21 14:35:56 -04:00
|
|
|
&loop ( integer )
|
|
|
|
DUP print-dec #2018 DEO
|
|
|
|
DUP #03 mod ?&>no-3
|
|
|
|
;dict/fizz print-str &>no-3
|
|
|
|
DUP #05 mod ?&>no-5
|
|
|
|
;dict/buzz print-str &>no-5
|
2022-11-10 12:08:21 -05:00
|
|
|
#0a18 DEO
|
2023-02-23 22:04:34 -05:00
|
|
|
INC GTHk ?&loop
|
2021-10-12 21:38:45 -04:00
|
|
|
POP2
|
2023-07-21 14:35:56 -04:00
|
|
|
( halt ) #010f DEO
|
|
|
|
BRK
|
2021-10-12 21:38:45 -04:00
|
|
|
|
2022-11-10 12:08:21 -05:00
|
|
|
@mod ( a b -- c )
|
2023-07-21 14:35:56 -04:00
|
|
|
DIVk MUL SUB JMP2r
|
2022-11-10 12:08:21 -05:00
|
|
|
|
|
|
|
@print-dec ( num -- )
|
2023-07-21 14:35:56 -04:00
|
|
|
( x0 ) DUP #0a DIV print-dec/num
|
|
|
|
( 0x ) #0a DIVk MUL SUB &num #30 ADD #18 DEO
|
|
|
|
JMP2r
|
2022-11-10 12:08:21 -05:00
|
|
|
|
|
|
|
@print-str ( addr* -- )
|
2023-07-21 14:35:56 -04:00
|
|
|
&while ( -- )
|
2022-11-10 12:08:21 -05:00
|
|
|
LDAk #18 DEO
|
2023-02-23 22:04:34 -05:00
|
|
|
INC2 LDAk ?&while
|
2023-07-21 14:35:56 -04:00
|
|
|
POP2 JMP2r
|
|
|
|
|
|
|
|
@dict ( strings )
|
|
|
|
&fizz "Fizz $1
|
|
|
|
&buzz "Buzz $1
|
2021-10-12 21:38:45 -04:00
|
|
|
|