0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-05 22:05:04 +00:00
uxn/projects/examples/exercises/fizzbuzz.tal

34 lines
602 B
Tal
Raw Normal View History

2023-07-21 18:35:56 +00:00
( FizzBuzz: From 1 to 100, for multiples of 3 print "Fizz", of 5 "Buzz" and for both "FizzBuzz" )
2021-10-13 01:38:45 +00:00
2023-07-21 18:35:56 +00:00
@on-reset ( -> )
2021-10-13 01:38:45 +00:00
#6400
2023-09-06 03:05:14 +00:00
&loop ( -- )
DUP <print-dec>
#2018 DEO
DUP #03 DIVk MUL SUB ?{ ;dict/fizz <print-str>/ }
DUP #05 DIVk MUL SUB ?{ ;dict/buzz <print-str>/ }
2022-11-10 17:08:21 +00:00
#0a18 DEO
INC GTHk ?&loop
2021-10-13 01:38:45 +00:00
POP2
2023-09-06 03:05:14 +00:00
( exit ) #800f DEO
2023-07-21 18:35:56 +00:00
BRK
2021-10-13 01:38:45 +00:00
2023-09-06 03:05:14 +00:00
@<print-dec> ( num -- )
( x0 ) DUP #0a DIV <print-num>
( 0x ) #0a DIVk MUL SUB
( >> )
2022-11-10 17:08:21 +00:00
2023-09-06 03:05:14 +00:00
@<print-num> ( num -- )
#30 ADD #18 DEO
2023-07-21 18:35:56 +00:00
JMP2r
2022-11-10 17:08:21 +00:00
2023-09-06 03:05:14 +00:00
@<print-str> ( addr* -- )
LDAk #18 DEO
INC2 & LDAk ?<print-str>
2023-07-21 18:35:56 +00:00
POP2 JMP2r
@dict ( strings )
&fizz "Fizz $1
&buzz "Buzz $1
2021-10-13 01:38:45 +00:00