commit e4d4c4830c83cb88691a3474e8556e9f57f6635d
parent f616b132d330bd960a2010ad257a4dce10cbeb9c
Author: Christian Ermann <christianermann@gmail.com>
Date: Tue, 5 Nov 2024 22:26:52 -0800
Add 'cells', 'cell+', and '*'
Diffstat:
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Dockerfile b/Dockerfile
@@ -42,7 +42,7 @@ COPY ns16550a.s .
COPY forth.s .
COPY forth.f .
COPY riscv32-virt.ld .
-RUN riscv64-unknown-elf-gcc -ggdb -static -nostdlib -nostdinc -nostartfiles -x assembler-with-cpp -march=rv32i -mabi=ilp32 -T riscv32-virt.ld -o forth.elf ns16550a.s forth.s
+RUN riscv64-unknown-elf-gcc -ggdb -static -nostdlib -nostdinc -nostartfiles -x assembler-with-cpp -march=rv32im -mabi=ilp32 -T riscv32-virt.ld -o forth.elf ns16550a.s forth.s
FROM build-tools as run-base
diff --git a/forth.s b/forth.s
@@ -535,11 +535,24 @@ defcode "-!", 2, 0, 0x24CD235B, sub_store, add_store
store_cell t0, 0(w)
next
+defcode "cells", 5, 0, 0xD94ACBB2, cells, sub_store
+ pop w
+ li x, cell
+ mul w, w, x
+ push w
+ next
+
+defcode "cell+", 5, 0, 0xB14A8CBA, cell_plus, cells
+ pop w
+ addi w, w, cell
+ push w
+ next
+
# -----------------------------------------------------------------------------
# dictionary management
# -----------------------------------------------------------------------------
-defcode "dp", 2, 0, 0x491CB0B9, dp, sub_store
+defcode "dp", 2, 0, 0x491CB0B9, dp, cell_plus
la w, _here
push w
next
@@ -681,6 +694,13 @@ defcode "-", 1, 0, 0x280C9438, minus, plus
push w
next
+defcode "*", 1, 0, 0x2F0C9F3D, times, minus
+ pop w
+ pop x
+ mul w, w, x
+ push w
+ next
+
defcode "or", 2, 0, 0x5D342984, or_, minus
pop w
pop x