mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-10-31 19:42:39 +00:00
43 lines
734 B
Tal
43 lines
734 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" )
|
|
|
|
%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
|