commit dfe96a0dec471106409b9cf9c9f0546035454550
parent 1bc0aada3515901f102e9cd7353c30b7777c564e
Author: Henry Wilson <m3henry@googlemail.com>
Date: Sat, 17 Jun 2017 13:17:08 +0100
got accept working properly
Diffstat:
M | compile | | | 2 | +- |
M | main.s | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
2 files changed, 62 insertions(+), 31 deletions(-)
diff --git a/compile b/compile
@@ -1,4 +1,4 @@
#! /bin/bash
-gcc -c main.s && ld main.o && rm main.o && ./a.out
+gcc -c main.s && ld main.o && rm main.o && echo "Testing, 123..." | ./a.out
echo "Returns:" $?
diff --git a/main.s b/main.s
@@ -15,17 +15,37 @@
.quad \val
.endm
-.macro string data
+.macro variable
+ do dovar
+ .quad 0
+.endm
+
+.macro string msg
do dostr
.quad 2f - 1f
-1: .ascii "\data\()"
+1: .ascii "\msg\()"
2:
.endm
+.macro say msg
+ string "\msg\()"
+ do print
+.endm
+
+.macro saycr msg
+ say "\msg\()\n"
+.endm
+
.macro scratch length
- do dostr
- .quad \length
- .skip \length
+ const 1f
+ goto 2f
+1: .skip \length
+2:
+.endm
+
+.macro goto label
+ do dogoto
+ .quad \label
.endm
.macro if label
@@ -54,7 +74,11 @@
.data
cold: forthword
-_cold: do abort
+_cold: saycr "aFORTH alpha"
+ const 0
+ do numtib
+ do store
+ do abort
abort: forthword
do quit
@@ -68,6 +92,7 @@ quit: forthword
do dottest
do inputtest
do dotdot
+ saycr "Done."
do halt
dottest: forthword
@@ -78,28 +103,23 @@ dottest: forthword
inputtest: forthword
do tib
- do dup
- do dup
- do load
- do swap
- const 8
- do plus
- do swap
- do dotdot
- do accept
- string "Read "
- do print
- do dot
- string " characters."
- do print
- do cr
- do print
+ do dup
+ const 80
+ say "Enter something: >"
+ do accept
do cr
+ say "Read "
+ do dup
+ do dot
+ saycr " characters."
+
+ say "["
+ do type
+ saycr "]"
endword
greet: forthword
- string "Hello, World!"
- do print
+ say "Hello, World!"
do cr
endword
@@ -128,13 +148,16 @@ star: forthword
endword
tib: forthword
-# scratch 80
- string "________________________________________________________________________________"
+ scratch 80
+ endword
+
+numtib: forthword
+ variable
endword
cr: forthword
- string "\n\r"
- do print
+ const '\n'
+ do emit
endword
dot: forthword
@@ -182,6 +205,8 @@ buff: .quad
stack: .skip 1024 #1048576
+# Codeword macros
+
.macro codeword
.quad . + 8
.endm
@@ -290,8 +315,8 @@ accept: codeword
mov $0, ARGA
mov (SP), ARGB
mov TOS, ARGC
- mov CMD, (SP)
syscall
+ mov CMD, (SP)
jmp _drop
# Do Stuff
@@ -302,6 +327,12 @@ docon: codeword
advance IP
jmp next
+dovar: codeword
+ _dup
+ mov IP, TOS
+ advance IP
+ jmp next
+
dostr: codeword
_dup
mov IP, TOS
@@ -309,7 +340,7 @@ dostr: codeword
advance IP
jmp next
-dojump: codeword
+dogoto: codeword
mov (IP), IP
jmp next