2022-03-25 13:29:45 -04:00
|
|
|
( FizzBuzz:
|
|
|
|
A program that prints the integers from 1 to 100.
|
2021-10-12 21:38:45 -04:00
|
|
|
for multiples of three, print "Fizz"
|
|
|
|
for multiples of five, print "Buzz"
|
|
|
|
for multiples of both three and five, print "FizzBuzz" )
|
|
|
|
|
2022-03-25 13:29:45 -04:00
|
|
|
|0100 ( -> ) @reset
|
2021-10-12 21:38:45 -04:00
|
|
|
|
|
|
|
#6400
|
|
|
|
&loop
|
2022-11-10 12:08:21 -05:00
|
|
|
( integer )
|
|
|
|
DUPk ,print-dec JSR #2018 DEO
|
|
|
|
( fizzbuzz )
|
2022-03-10 13:05:00 -05:00
|
|
|
DUP #03 ,mod JSR ,&no3 JCN ;s/fizz ,print-str JSR &no3
|
|
|
|
DUP #05 ,mod JSR ,&no5 JCN ;s/buzz ,print-str JSR &no5
|
2022-11-10 12:08:21 -05:00
|
|
|
#0a18 DEO
|
2021-10-12 21:38:45 -04:00
|
|
|
INC GTHk ,&loop JCN
|
|
|
|
POP2
|
2022-11-10 12:08:21 -05:00
|
|
|
( halt )
|
|
|
|
#010f DEO
|
2021-10-12 21:38:45 -04:00
|
|
|
|
|
|
|
BRK
|
|
|
|
|
2022-11-10 12:08:21 -05:00
|
|
|
@mod ( a b -- c )
|
|
|
|
DIVk MUL SUB
|
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@print-dec ( num -- )
|
|
|
|
#0a DIV ,&emit JSR
|
|
|
|
#0a ,mod JSR
|
|
|
|
&emit
|
|
|
|
#30 ADD #18 DEO
|
|
|
|
JMP2r
|
|
|
|
|
|
|
|
@print-str ( addr* -- )
|
|
|
|
&while
|
|
|
|
LDAk #18 DEO
|
|
|
|
INC2 LDAk ,&while JCN
|
|
|
|
POP2
|
|
|
|
JMP2r
|
2021-10-12 21:38:45 -04:00
|
|
|
|
2022-03-25 13:29:45 -04:00
|
|
|
@s &fizz "Fizz $1 &buzz "Buzz $1
|