0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-22 22:05:11 +00:00

(exercises) Housekeeping

This commit is contained in:
neauoire 2022-11-10 09:08:21 -08:00
parent da5e581442
commit 4270d48422
3 changed files with 35 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

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