uxn/projects/examples/exercises/fizzbuzz.tal

41 lines
683 B
Tal
Raw Normal View History

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