about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorNaren Ratan <narenratan@gmail.com>2019-12-01 22:47:27 +0000
committerNaren Ratan <narenratan@gmail.com>2019-12-01 22:47:27 +0000
commit72e142b32380cb1c59ea9846b4f5994487e88132 (patch)
treef244736c90a2a79f28f79fb31be594ccc498cb38
parent032204d951e191771ce6cd99ecf5118ee1e1dce5 (diff)
downloadjonesforth_arm64_apl-72e142b32380cb1c59ea9846b4f5994487e88132.tar.gz
Add counter register
-rw-r--r--jonesforth.S7
1 files changed, 7 insertions, 0 deletions
diff --git a/jonesforth.S b/jonesforth.S
index c585eff..99733ce 100644
--- a/jonesforth.S
+++ b/jonesforth.S
@@ -26,6 +26,8 @@
 #define E x17			// End pointer
 #define OUTB x11		// Output buffer pointer
 
+#define n x10           // Count register
+
 // Stack macros
 .macro push s,x; str \x,[\s,-8]!; .endm		// e.g. push D,x0 pushes x0 to data stack
 .macro push2 s,x,y; stp \y,\x,[\s,-16]!; .endm	// One instruction, two pushes!
@@ -109,6 +111,10 @@ def "D0"; push D,D0; NEXT
 def "R0"; push D,R0; NEXT
 def DOCOL; push D,PDOC; NEXT
 
+def "n"; push D,n; NEXT; 						def "n!"; pop D,n; NEXT
+def "n+"; add n,n,1; NEXT; 						def "n-"; sub n,n,1; NEXT
+def "n0"; mov n,0; NEXT
+
 def KEY; bl key; push D,x0; NEXT;
 
 key:	cmp K,E; b.ge fill; ldrb w0,[K],1; ret			// Fill buffer if exhausted and read next character
@@ -238,6 +244,7 @@ _start:	mov D,sp					// Initialize Data stack pointer
 	adr B,b; mov K,B; mov E,B			// Initialize Buffer, Key, End pointers
 	adr OUTB,outb					// Initialize output buffer pointer
 	mov D0,D; mov R0,R				// Initialize stack top pointers
+	mov n,0;                                        // Initialize count register
 	adr PLIT,LIT; adr PDOC,docol			// Initialize LIT and DOCOL pointers
 	movi VC0A.16b,10; movi VC0F.16b,0x0F		// Initialize constant vector registers
 	movi VC20.16b,32; movi VC30.16b,'0'