(fizzbuzz.tal) Migrated to immediate opcodes

This commit is contained in:
Devine Lu Linvega 2023-02-23 19:04:34 -08:00
parent 42ade9e8c8
commit 85e4383332
1 changed files with 11 additions and 13 deletions

View File

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