(fizzbuzz.tal) Migrated to immediate opcodes
This commit is contained in:
parent
42ade9e8c8
commit
85e4383332
|
@ -4,21 +4,19 @@
|
|||
for multiples of five, print "Buzz"
|
||||
for multiples of both three and five, print "FizzBuzz" )
|
||||
|
||||
|0100 ( -> ) @reset
|
||||
|
||||
|0100 ( -> )
|
||||
#6400
|
||||
&loop
|
||||
( integer )
|
||||
DUPk ,print-dec JSR #2018 DEO
|
||||
DUPk print-dec #2018 DEO
|
||||
( fizzbuzz )
|
||||
DUP #03 ,mod JSR ,&no3 JCN ;s/fizz ,print-str JSR &no3
|
||||
DUP #05 ,mod JSR ,&no5 JCN ;s/buzz ,print-str JSR &no5
|
||||
DUP #03 mod ?&no3 ;dict/fizz print-str &no3
|
||||
DUP #05 mod ?&no5 ;dict/buzz print-str &no5
|
||||
#0a18 DEO
|
||||
INC GTHk ,&loop JCN
|
||||
INC GTHk ?&loop
|
||||
POP2
|
||||
( halt )
|
||||
#010f DEO
|
||||
|
||||
BRK
|
||||
|
||||
@mod ( a b -- c )
|
||||
|
@ -26,17 +24,17 @@ BRK
|
|||
JMP2r
|
||||
|
||||
@print-dec ( num -- )
|
||||
#0a DIV ,&emit JSR
|
||||
#0a ,mod JSR
|
||||
&emit
|
||||
#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 JCN
|
||||
INC2 LDAk ?&while
|
||||
POP2
|
||||
JMP2r
|
||||
|
||||
@s &fizz "Fizz $1 &buzz "Buzz $1
|
||||
@dict &fizz "Fizz $1 &buzz "Buzz $1
|
||||
|
|
Loading…
Reference in New Issue