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

(subleq.tal) Ported to immediate modes

This commit is contained in:
Devine Lu Linvega 2023-06-27 11:27:27 -07:00
parent f3674b2562
commit 49d74b89d0

View file

@ -1,46 +1,41 @@
( Subleq: ( Subleq: The subleq instruction subtracts the contents at address a from the contents at address b, stores the result at address b, and then, if the result is not positive, jumps to address c. If the result is positive, execution proceeds to the next instruction in sequence. )
The subleq instruction subtracts the contents at address a
from the contents at address b, stores the result at address b,
and then, if the result is not positive, jumps to address c.
If the result is positive, execution proceeds to the next instruction
in sequence. )
|0000 |0100
@a $2 @b $2 @c $2
|0100 ( -> ) @reset
@on-reset ( -> )
#0000 #0000
&while &while ( -- )
,eval JSR eval DUP2 #8000 LTH2 ?&while
DUP2 #8000 LTH2 ,&while JCN
POP2 POP2
( halt ) #010f DEO ( halt ) #010f DEO
BRK BRK
@eval ( ip* -- ip* ) @eval ( ip* -- ip* )
DUP2 get ,&a STR2
DUP2 ,&get JSR .a STZ2 INC2 DUP2 get ,&b STR2
INC2 DUP2 ,&get JSR .b STZ2 INC2 DUP2 get ,&c STR2
INC2 DUP2 ,&get JSR .c STZ2
INC2 INC2
( I/O ) ( | I/O )
.a LDZ2 #ffff EQU2 ,&input JCN [ LIT2 &a $2 ] #ffff EQU2 ?&input
.b LDZ2 #ffff EQU2 ,&output JCN [ LIT2 &b $2 ] #ffff EQU2 ?&output
( SUBLEQ ) ( | SUBLEQ )
.b LDZ2 STH2k ,&get JSR .a LDZ2 ,&get JSR SUB2 STH2r DUP2 ADD2 ;program ADD2 STA2 ( sub ) ,&b LDR2 get ,&a LDR2 get SUB2 DUP2
( SET ) ( write ) ,&b LDR2 DUP2 ADD2 ;program ADD2 STA2
.b LDZ2 ,&get JSR #0001 SUB2 #8000 LTH2 ,&end JCN POP2 .c LDZ2 &end ( leq ) #0001 SUB2 #8000 LTH2 ?&end
POP2 [ LIT2 &c $2 ] &end JMP2r
&input ( -- )
( TODO ) JMP2r
&output ( -- )
,&a LDR2 get NIP #18 DEO
JMP2r JMP2r
&input ( -- ) JMP2r
&output ( -- ) .a LDZ2 ,&get JSR NIP #18 DEO JMP2r @get ( a* -- b* )
&get ( a* -- b* ) DUP2 ADD2 ;program ADD2 LDA2 JMP2r DUP2 ADD2 ;program ADD2 LDA2 JMP2r
@program ( hello world ) @program ( hello world )
[
000f 0011 ffff 0011 ffff ffff 0010 0001 000f 0011 ffff 0011 ffff ffff 0010 0001
ffff 0010 0003 ffff 000f 000f 0000 0000 ffff 0010 0003 ffff 000f 000f 0000 0000
ffff 0048 0065 006c 006c 006f 002c 0020 ffff 0048 0065 006c 006c 006f 002c 0020
0077 006f 0072 006c 0064 0021 000a 0000 0077 006f 0072 006c 0064 0021 000a 0000 ]