commit 169ab026831af1a4bbaeabd3da5f3fd5f4ea814d
parent dbc8e2221b8ec883806d3631788e1aea219798ec
Author: Henry Wilson <m3henry@googlemail.com>
Date: Sun, 18 Jun 2017 17:35:47 +0100
early word parsing
Diffstat:
M | main.s | | | 66 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
M | makefile | | | 2 | +- |
2 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/main.s b/main.s
@@ -20,6 +20,17 @@
.quad 0
.endm
+.macro get var
+ do \var
+ do fetch
+.endm
+
+.macro set var value
+ const \value
+ do \var
+ do store
+.endm
+
.macro string msg
do dostr
.quad 2f - 1f
@@ -75,9 +86,7 @@
cold: forthword
_cold: saycr "aFORTH alpha \xe2\x9c\x93"
- const 0
- do numtib
- do store
+ set numtib 0
do abort
abort: forthword
@@ -91,6 +100,12 @@ quit: forthword
do execute
do dottest
do inputtest
+ set numin 0
+ 1: do getword
+ get numin
+ get numtib
+ do less
+ if 1b
do dotdot
saycr "Done."
do halt
@@ -107,6 +122,9 @@ inputtest: forthword
const 80
say "Enter something: >"
do accept
+ do dup
+ do numtib
+ do store
do cr
say "Read "
do dup
@@ -118,6 +136,27 @@ inputtest: forthword
saycr "]"
endword
+getword: forthword
+1: get numin
+ get numtib
+ do gequal
+ if 3f
+ do tib
+ get numin
+ do plus
+ do fetchb
+ do numin
+ do incaddr
+ do dup
+ const ' '
+ do equal
+ if 2f
+ do emit
+ goto 1b
+2: do drop
+3: do cr
+ endword
+
greet: forthword
say "Hello, World!"
do cr
@@ -147,6 +186,10 @@ star: forthword
do emit
endword
+pad: forthword
+ scratch 90
+ endword
+
tib: forthword
scratch 80
endword
@@ -155,6 +198,10 @@ numtib: forthword
variable
endword
+numin: forthword
+ variable
+ endword
+
cr: forthword
const '\n'
do emit
@@ -385,12 +432,13 @@ dountil: codeword
# Memory management
-load: codeword
+fetch: codeword
mov (TOS), TOS
jmp next
-atb: codeword
+fetchb: codeword
movb (TOS), TOSB
+ and $0xFF, TOS
jmp next
store: codeword
@@ -472,6 +520,14 @@ dec: codeword
dec TOS
jmp next
+incaddr: codeword
+ incq (TOS)
+ jmp _drop
+
+decaddr: codeword
+ decq (TOS)
+ jmp _drop
+
negate: codeword
neg TOS
jmp next
diff --git a/makefile b/makefile
@@ -1,6 +1,6 @@
all: bin/aFORTH
@echo Testing...
- @/bin/echo -ne "Testing, 123! \xe2\x9c\x93" | bin/aFORTH
+ @/bin/echo -ne "WORD PHRASE WORD BOX" | bin/aFORTH
bin/aFORTH: obj/main.o
@echo Linking...