0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-17 19:45:11 +00:00
uxn/projects/examples/exercises/fizzbuzz.tal
2023-02-23 19:04:34 -08:00

40 lines
683 B
Tal

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