0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-12-01 02:03:02 +00:00
uxn/projects/examples/exercises/fizzbuzz.tal

44 lines
734 B
Tal
Raw Normal View History

2021-10-13 01:38:45 +00:00
( 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" )
%MOD { DIVk MUL SUB }
%HALT { #01 #0f DEO }
%EMIT { #18 DEO }
%RTN { JMP2r }
@program
|0100 ( -> )
#6400
&loop
LITr 00
DUP #03 MOD ,&no3 JCN ;fizz-txt ;print-str JSR2 INCr &no3
DUP #05 MOD ,&no5 JCN ;buzz-txt ;print-str JSR2 INCr &no5
STHr ,&resume JCN
( print decimal )
DUPk #0a DIV #30 ADD EMIT
#0a MOD #30 ADD EMIT
&resume
( add linebreak ) #0a EMIT
INC GTHk ,&loop JCN
POP2
HALT
BRK
@print-str ( addr* -- )
&loop
LDAk EMIT
INC2 LDAk ,&loop JCN
POP2
RTN
@fizz-txt "Fizz $1
@buzz-txt "Buzz $1