(fizzbuzz.tal) Removed macros from fizzbuzz

This commit is contained in:
neauoire 2022-03-10 10:05:00 -08:00
parent cfedb19dca
commit 162400cb54
1 changed files with 18 additions and 29 deletions

View File

@ -3,41 +3,30 @@
for multiples of five, print "Buzz" for multiples of five, print "Buzz"
for multiples of both three and five, print "FizzBuzz" ) for multiples of both three and five, print "FizzBuzz" )
%MOD { DIVk MUL SUB } |0100 ( -> ) @program
%HALT { #01 #0f DEO }
%EMIT { #18 DEO }
%RTN { JMP2r }
@program
|0100 ( -> )
#6400 #6400
&loop &loop
LITr 00 ( dec )
DUP #03 MOD ,&no3 JCN ;fizz-txt ;print-str JSR2 INCr &no3 DUPk #0a DIV ,print-num JSR
DUP #05 MOD ,&no5 JCN ;buzz-txt ;print-str JSR2 INCr &no5 #0a ,mod JSR ,print-num JSR
STHr ,&resume JCN ( space )
( print decimal ) #2018 DEO
DUPk #0a DIV #30 ADD EMIT ( text )
#0a MOD #30 ADD EMIT DUP #03 ,mod JSR ,&no3 JCN ;s/fizz ,print-str JSR &no3
&resume DUP #05 ,mod JSR ,&no5 JCN ;s/buzz ,print-str JSR &no5
( add linebreak ) #0a EMIT ( linebreak ) #0a18 DEO
INC GTHk ,&loop JCN INC GTHk ,&loop JCN
POP2 POP2
( halt )
HALT #010f DEO
BRK BRK
@print-str ( addr* -- ) @mod ( a b -- c ) DIVk MUL SUB JMP2r
@print-num ( num -- ) #30 ADD #18 DEO JMP2r
@print-str ( addr* -- ) &loop LDAk #18 DEO INC2 LDAk ,&loop JCN POP2 JMP2r
&loop @s
LDAk EMIT &fizz "Fizz $1
INC2 LDAk ,&loop JCN &buzz "Buzz $1
POP2
RTN
@fizz-txt "Fizz $1
@buzz-txt "Buzz $1