diff --git a/projects/examples/exercises/fib.tal b/projects/examples/exercises/fib.tal index 9b5cb99..fc35d37 100644 --- a/projects/examples/exercises/fib.tal +++ b/projects/examples/exercises/fib.tal @@ -6,14 +6,15 @@ #0000 INC2k ADD2k &loop - ( print ) DUP2 ,print JSR - ( linebreak ) #0a18 DEO + DUP2 ,print-hex JSR #0a18 DEO ADD2k LTH2k ,&loop JCN - ( halt ) #010f DEO + + ( halt ) + #010f DEO BRK -@print ( short* -- ) +@print-hex ( short* -- ) SWP ,&byte JSR &byte ( byte -- ) DUP #04 SFT ,&char JSR diff --git a/projects/examples/exercises/fizzbuzz.tal b/projects/examples/exercises/fizzbuzz.tal index d1f5c59..96a7d34 100644 --- a/projects/examples/exercises/fizzbuzz.tal +++ b/projects/examples/exercises/fizzbuzz.tal @@ -8,20 +8,35 @@ #6400 &loop - ( dec ) DUPk ,print-dec JSR - ( space ) #2018 DEO + ( integer ) + DUPk ,print-dec JSR #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 - ( linebreak ) #0a18 DEO + #0a18 DEO INC GTHk ,&loop JCN POP2 - ( halt ) #010f DEO + ( halt ) + #010f DEO BRK -@mod ( a b -- c ) DIVk MUL SUB JMP2r -@print-dec ( num -- ) #0a DIV ,print-num JSR #0a ,mod JSR -@print-num ( num -- ) #30 ADD #18 DEO JMP2r -@print-str ( addr* -- ) &loop LDAk #18 DEO INC2 LDAk ,&loop JCN POP2 JMP2r +@mod ( a b -- c ) + DIVk MUL SUB +JMP2r + +@print-dec ( num -- ) + #0a DIV ,&emit JSR + #0a ,mod JSR + &emit + #30 ADD #18 DEO +JMP2r + +@print-str ( addr* -- ) + &while + LDAk #18 DEO + INC2 LDAk ,&while JCN + POP2 +JMP2r @s &fizz "Fizz $1 &buzz "Buzz $1 diff --git a/projects/examples/exercises/primes.tal b/projects/examples/exercises/primes.tal index 3b9a7d9..7c95e24 100644 --- a/projects/examples/exercises/primes.tal +++ b/projects/examples/exercises/primes.tal @@ -18,20 +18,17 @@ BRK @is-prime ( number* -- flag ) - DUP2 #0001 EQU2 ,&fail JCN - STH2k - ( range ) #01 SFT2 #0002 + DUP2 ,&t STR2 + ( range ) #01 SFT2 #0002 LTH2k ,&fail JCN &loop - STH2kr OVR2 ( mod2 ) [ DIV2k MUL2 SUB2 ] ORA ,&continue JCN - POP2 POP2 - POP2r #00 JMP2r - &continue + [ LIT2 &t $2 ] OVR2 + ( mod2 ) DIV2k MUL2 SUB2 + ORA #00 EQU ,&fail JCN INC2 GTH2k ,&loop JCN - POP2 POP2 - POP2r #01 + POP2 POP2 #01 JMP2r - &fail POP2 #00 JMP2r + &fail POP2 POP2 #00 JMP2r @print ( short* -- )