forth-riscv

My forth
git clone git://git.electrosoup.com/forth-riscv
Log | Files | Refs

commit 5269bade53c7b5ac3f16211b7f8c13c61b3d6436
parent 9dd1577a009cdc97fe318d0e96bc62731736d68c
Author: Christian Ermann <christianermann@gmail.com>
Date:   Wed, 30 Oct 2024 12:29:50 -0700

Add 'memory access', 'dictionary management', and 'stack manipulation' sections

Diffstat:
Mforth.s | 56++++++++++++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/forth.s b/forth.s @@ -382,6 +382,10 @@ _quit_top: .int interpret .int branch, _quit_top +# ----------------------------------------------------------------------------- +# memory access +# ----------------------------------------------------------------------------- + defcode "!", 1, 0, 0x240C8DEC, store, quit pop w # address pop x # value @@ -422,6 +426,10 @@ defcode "-!", 2, 0, 0x24CD235B, sub_store, add_store store_cell t0, 0(w) next +# ----------------------------------------------------------------------------- +# dictionary management +# ----------------------------------------------------------------------------- + defcode "dp", 2, 0, 0x491CB0B9, dp, sub_store la w, _here push w @@ -444,6 +452,32 @@ defcode "lit", 3, 0, 0x404CD5B6, lit, latest push w next +defword "allot", 5, 0, 0xADB1A69F, allot, drop + .int dp, add_store + .int exit + +defword ",", 1, 0, 0x290C95CB, comma, allot + .int here, store # store value + .int lit, cell, allot # increment 'here' + .int exit + +defword "c,", 2, 0, 0xA32A0A5A, char_comma, comma + .int here, char_store # store value + .int lit, 1, allot # increment 'here' + .int exit + +defcode "align", 5, 0, 0xC73174DF, align, aligned + la w, _here + load_cell x, 0(w) + addi x, x, 3 + andi x, x, 0xFFFFFFFC + store_cell x, 0(w) + next + +# ----------------------------------------------------------------------------- +# stack manipulation +# ----------------------------------------------------------------------------- + defcode "dup", 3, 0, 0xD330F226, dup, lit load_cell w, 0(psp) push w @@ -467,20 +501,6 @@ defcode "2dup", 3, 0, 0xD330F226, two_dup, lit push w next -defword "allot", 5, 0, 0xADB1A69F, allot, drop - .int dp, add_store - .int exit - -defword ",", 1, 0, 0x290C95CB, comma, allot - .int here, store # store value - .int lit, cell, allot # increment 'here' - .int exit - -defword "c,", 2, 0, 0xA32A0A5A, char_comma, comma - .int here, char_store # store value - .int lit, 1, allot # increment 'here' - .int exit - defcode "aligned", 7, 0, 0xC73174DF, aligned, char_comma pop w addi w, w, 3 @@ -488,14 +508,6 @@ defcode "aligned", 7, 0, 0xC73174DF, aligned, char_comma push w next -defcode "align", 5, 0, 0xC73174DF, align, aligned - la w, _here - load_cell x, 0(w) - addi x, x, 3 - andi x, x, 0xFFFFFFFC - store_cell x, 0(w) - next - defcode "+", 1, 0, 0xC4ADC675, plus, align pop w pop x