Browse code

(subleq.tal) Ported to immediate modes

Devine Lu Linvega authored on 27/06/2023 18:27:27
Showing 1 changed files
... ...
@@ -1,46 +1,41 @@
1
-( Subleq:
2
-	The subleq instruction subtracts the contents at address a
3
-	from the contents at address b, stores the result at address b,
4
-	and then, if the result is not positive, jumps to address c.
5
-	If the result is positive, execution proceeds to the next instruction
6
-	in sequence. )
1
+( 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. )
7 2
 
8
-|0000
9
-
10
-	@a $2 @b $2 @c $2
11
-
12
-|0100 ( -> ) @reset
3
+|0100
13 4
 
5
+@on-reset ( -> )
14 6
 	#0000
15
-	&while
16
-		,eval JSR
17
-		DUP2 #8000 LTH2 ,&while JCN
7
+	&while ( -- )
8
+		eval DUP2 #8000 LTH2 ?&while
18 9
 	POP2
19 10
 	( halt ) #010f DEO
20
-
21
-BRK
11
+	BRK
22 12
 
23 13
 @eval ( ip* -- ip* )
24
-
25
-	DUP2 ,&get JSR .a STZ2
26
-	INC2 DUP2 ,&get JSR .b STZ2
27
-	INC2 DUP2 ,&get JSR .c STZ2
14
+	DUP2 get ,&a STR2
15
+	INC2 DUP2 get ,&b STR2
16
+	INC2 DUP2 get ,&c STR2
28 17
 	INC2
29
-	( I/O )
30
- 	.a LDZ2 #ffff EQU2 ,&input JCN
31
-	.b LDZ2 #ffff EQU2 ,&output JCN
32
-	( SUBLEQ )
33
-	.b LDZ2 STH2k ,&get JSR .a LDZ2 ,&get JSR SUB2 STH2r DUP2 ADD2 ;program ADD2 STA2
34
-	( SET )
35
-	.b LDZ2 ,&get JSR #0001 SUB2 #8000 LTH2 ,&end JCN POP2 .c LDZ2 &end
36
-
37
-JMP2r
38
-	&input ( -- ) JMP2r
39
-	&output ( -- ) .a LDZ2 ,&get JSR NIP #18 DEO JMP2r
40
-	&get ( a* -- b* ) DUP2 ADD2 ;program ADD2 LDA2 JMP2r
18
+	( | I/O )
19
+	[ LIT2 &a $2 ] #ffff EQU2 ?&input
20
+	[ LIT2 &b $2 ] #ffff EQU2 ?&output
21
+	( | SUBLEQ )
22
+	( sub ) ,&b LDR2 get ,&a LDR2 get SUB2 DUP2
23
+	( write ) ,&b LDR2 DUP2 ADD2 ;program ADD2 STA2
24
+	( leq ) #0001 SUB2 #8000 LTH2 ?&end
25
+	POP2 [ LIT2 &c $2 ] &end JMP2r
26
+	&input ( -- )
27
+		( TODO ) JMP2r
28
+	&output ( -- )
29
+		,&a LDR2 get NIP #18 DEO
30
+		JMP2r
31
+
32
+@get ( a* -- b* )
33
+	DUP2 ADD2 ;program ADD2 LDA2 JMP2r
41 34
 
42 35
 @program ( hello world )
36
+	[
43 37
 	000f 0011 ffff 0011 ffff ffff 0010 0001
44 38
 	ffff 0010 0003 ffff 000f 000f 0000 0000
45 39
 	ffff 0048 0065 006c 006c 006f 002c 0020
46
-	0077 006f 0072 006c 0064 0021 000a 0000
40
+	0077 006f 0072 006c 0064 0021 000a 0000 ]
41
+