uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 4270d48422188e6560a89aba2a9478ace0c64f05
parent da5e5814425a8a00ba0fb9089bd967fc6e632be0
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 10 Nov 2022 09:08:21 -0800

(exercises) Housekeeping

Diffstat:
Mprojects/examples/exercises/fib.tal | 9+++++----
Mprojects/examples/exercises/fizzbuzz.tal | 31+++++++++++++++++++++++--------
Mprojects/examples/exercises/primes.tal | 17+++++++----------
3 files changed, 35 insertions(+), 22 deletions(-)

diff --git 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 @@ -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 @@ -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* -- )