(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 #0000 INC2k ADD2k
&loop &loop
( print ) DUP2 ,print JSR DUP2 ,print-hex JSR #0a18 DEO
( linebreak ) #0a18 DEO
ADD2k LTH2k ,&loop JCN ADD2k LTH2k ,&loop JCN
( halt ) #010f DEO
( halt )
#010f DEO
BRK BRK
@print ( short* -- ) @print-hex ( short* -- )
SWP ,&byte JSR SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR &byte ( byte -- ) DUP #04 SFT ,&char JSR

View File

@ -8,20 +8,35 @@
#6400 #6400
&loop &loop
( dec ) DUPk ,print-dec JSR ( integer )
( space ) #2018 DEO DUPk ,print-dec JSR #2018 DEO
( fizzbuzz )
DUP #03 ,mod JSR ,&no3 JCN ;s/fizz ,print-str JSR &no3 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 #05 ,mod JSR ,&no5 JCN ;s/buzz ,print-str JSR &no5
( linebreak ) #0a18 DEO #0a18 DEO
INC GTHk ,&loop JCN INC GTHk ,&loop JCN
POP2 POP2
( halt ) #010f DEO ( halt )
#010f DEO
BRK BRK
@mod ( a b -- c ) DIVk MUL SUB JMP2r @mod ( a b -- c )
@print-dec ( num -- ) #0a DIV ,print-num JSR #0a ,mod JSR DIVk MUL SUB
@print-num ( num -- ) #30 ADD #18 DEO JMP2r JMP2r
@print-str ( addr* -- ) &loop LDAk #18 DEO INC2 LDAk ,&loop JCN POP2 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 @s &fizz "Fizz $1 &buzz "Buzz $1

View File

@ -18,20 +18,17 @@ BRK
@is-prime ( number* -- flag ) @is-prime ( number* -- flag )
DUP2 #0001 EQU2 ,&fail JCN DUP2 ,&t STR2
STH2k ( range ) #01 SFT2 #0002 LTH2k ,&fail JCN
( range ) #01 SFT2 #0002
&loop &loop
STH2kr OVR2 ( mod2 ) [ DIV2k MUL2 SUB2 ] ORA ,&continue JCN [ LIT2 &t $2 ] OVR2
POP2 POP2 ( mod2 ) DIV2k MUL2 SUB2
POP2r #00 JMP2r ORA #00 EQU ,&fail JCN
&continue
INC2 GTH2k ,&loop JCN INC2 GTH2k ,&loop JCN
POP2 POP2 POP2 POP2 #01
POP2r #01
JMP2r JMP2r
&fail POP2 #00 JMP2r &fail POP2 POP2 #00 JMP2r
@print ( short* -- ) @print ( short* -- )