additional part-cell primitives
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Sat, 12 Jun 2021 12:48:16 +0000 (22:48 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Sat, 12 Jun 2021 12:48:16 +0000 (22:48 +1000)
adoc/p_Dcomma.adoc [new file with mode: 0644]
adoc/p_Dget.adoc [new file with mode: 0644]
adoc/p_Dput.adoc [new file with mode: 0644]
adoc/p_Wcomma.adoc [new file with mode: 0644]
adoc/p_Wget.adoc [new file with mode: 0644]
adoc/p_Wput.adoc [new file with mode: 0644]
compile.asm
memory.asm
reference.adoc
stdio.asm
wordindex.adoc

diff --git a/adoc/p_Dcomma.adoc b/adoc/p_Dcomma.adoc
new file mode 100644 (file)
index 0000000..db3e821
--- /dev/null
@@ -0,0 +1,23 @@
+// compile.asm:        WORD p_Dcomma,'D,',fasm
+
+anchor:p_Dcomma[]
+
+=== Word: D,
+
+
+....
+Data stack: ( v -- )
+....
+
+"D," (D-comma) is a function word that puts a "double word"
+(double-byte) on the <<p_here,HERE>> heap. The four least significant
+bytes of the value are put at the current free head address, which
+also is incremented accordingly.
+
+====
+.Definition concept for D,
+****
+: D, HERE @ 4 ALLOT D! ;
+****
+====
+
diff --git a/adoc/p_Dget.adoc b/adoc/p_Dget.adoc
new file mode 100644 (file)
index 0000000..7e68ea0
--- /dev/null
@@ -0,0 +1,13 @@
+// memory.asm: WORD p_Dget, 'D@',fasm
+
+anchor:p_Dget[]
+
+=== Word: D@
+
+....
+Data stack: ( a -- v )
+....
+
+"D@" is a function word that pushes the "double word" (4-byte) value v
+from the address a.
+
diff --git a/adoc/p_Dput.adoc b/adoc/p_Dput.adoc
new file mode 100644 (file)
index 0000000..5ea8095
--- /dev/null
@@ -0,0 +1,13 @@
+// memory.asm: WORD p_Dput, 'D!',fasm
+
+anchor:p_Dput[]
+
+=== Word: D!
+
+....
+Data stack: ( v a -- )
+....
+
+"D!" is a function word that stores the "doublw word" (4-byte) value v
+(the four least significant bytes of the cell) at the address a.
+
diff --git a/adoc/p_Wcomma.adoc b/adoc/p_Wcomma.adoc
new file mode 100644 (file)
index 0000000..979dcb2
--- /dev/null
@@ -0,0 +1,23 @@
+// compile.asm:        WORD p_Wcomma,'W,',fasm
+
+anchor:p_Wcomma[]
+
+=== Word: W,
+
+
+....
+Data stack: ( v -- )
+....
+
+"W," (W-comma) is a function word that puts a "word" (double-byte) on
+the <<p_here,HERE>> heap. The two least significant bytes of the value
+are put at the current free head address, which also is incremented
+accordingly.
+
+====
+.Definition concept for W,
+****
+: W, HERE @ 2 ALLOT W! ;
+****
+====
+
diff --git a/adoc/p_Wget.adoc b/adoc/p_Wget.adoc
new file mode 100644 (file)
index 0000000..9a59576
--- /dev/null
@@ -0,0 +1,13 @@
+// memory.asm: WORD p_Wget, 'W@',fasm
+
+anchor:p_Wget[]
+
+=== Word: W@
+
+....
+Data stack: ( a -- v )
+....
+
+"W@" is a function word that pushes the "word" (double-byte) value v
+from the address a.
+
diff --git a/adoc/p_Wput.adoc b/adoc/p_Wput.adoc
new file mode 100644 (file)
index 0000000..3fb2ca8
--- /dev/null
@@ -0,0 +1,13 @@
+// memory.asm: WORD p_Wput, 'W!',fasm
+
+anchor:p_Wput[]
+
+=== Word: W!
+
+....
+Data stack: ( v a -- )
+....
+
+"W!" is a function word that stores the "word" (2-byte) value v (the
+two least significant bytes of the cell) at the address a.
+
index ff5d853421005525e02035f3374abadc0a890390..d99504c8131f934150d9ebc8c59dcfe358357873 100644 (file)
@@ -57,15 +57,41 @@ p_quote_end:
        ;; Compile down " LIT value "
        dq p_literal, p_literal, p_comma,p_quote, p_comma, p_return
 
-       WORD p_comma,','
-       ;; ( v -- )
-       ;; Put cell value onto the heap and advance "HERE"
-       dq p_here, p_literal, 8, p_get_n_increment, p_put, p_return
-
        WORD p_Ccomma,'C,'
        ;; ( c -- )
        ;; Put byte value onto the heap and advance "HERE"
-       dq p_here, p_Cput, p_literal, 1, p_here, p_put_plus, p_return
+       mov rax,[p_here_DFA]
+       pop rbx
+       mov byte [rax],bl
+       inc qword [p_here_DFA]
+       next
+
+       WORD p_Wcomma,'W,'
+       ;; ( c -- )
+       ;; Put byte value onto the heap and advance "HERE"
+       mov rax,[p_here_DFA]
+       pop rbx
+       mov word [rax],bx
+       add qword [p_here_DFA],2
+       next
+
+       WORD p_Dcomma,'D,'
+       ;; ( d -- )
+       ;; Put byte value onto the heap and advance "HERE"
+       mov rax,[p_here_DFA]
+       pop rbx
+       mov dword [rax],ebx
+       add qword [p_here_DFA],4
+       next
+
+       WORD p_comma,','
+       ;; ( v -- )
+       ;; Put byte value onto the heap and advance "HERE"
+       mov rax,[p_here_DFA]
+       pop rbx
+       mov qword [rax],rbx
+       add qword [p_here_DFA],8
+       next
 
        WORD p_does,"DOES>",fasm,IMMEDIATE
        ;; ( -- )
index 4fe4772f76c38b3652e4308b1941ca1871541b27..eb84af7feb42e98616bdfb6e9f01d2e1a5d47333 100644 (file)
        mov byte [rax], bl
        next
 
+       WORD p_Wget, 'W@',fasm
+       ;; ( addr -- v )
+       ;; Load the (unsigned) double-byte v from address addr.
+       pop rax
+       mov bx,[rax]
+       push 0
+       mov word [rsp],bx
+       next
+       
+       WORD p_Wput, 'W!',fasm
+       ;; ( v addr -- )
+       ;; Store byte value v at address addr.
+       pop rax
+       pop rbx
+       mov word [rax], bx
+       next
+
+       WORD p_Dget, 'D@',fasm
+       ;; ( addr -- v )
+       ;; Load the (unsigned) double-byte v from address addr.
+       pop rax
+       mov ebx,[rax]
+       push 0
+       mov dword [rsp],ebx
+       next
+       
+       WORD p_Dput, 'D!',fasm
+       ;; ( v addr -- )
+       ;; Store byte value v at address addr.
+       pop rax
+       pop rbx
+       mov dword [rax], ebx
+       next
+
        WORD p_2get, '2@',fasm
        ;; ( addr -- v2 v1 )
        ;; Load the cell pair {v1,v2} from address addr.
index 7f1100eeb6a75bbe8f30ff95a22da0f8a1e8ab86..c4b512026e5457d975d13ae664f845d871e461bd 100644 (file)
@@ -31,12 +31,24 @@ include::adoc/p_2swap.adoc[]
 include::separator.adoc[]
 include::adoc/p_Ccomma.adoc[]
 include::separator.adoc[]
+include::adoc/p_Wcomma.adoc[]
+include::separator.adoc[]
+include::adoc/p_Dcomma.adoc[]
+include::separator.adoc[]
 include::adoc/p_cfa2tfa.adoc[]
 include::separator.adoc[]
 include::adoc/p_Cget.adoc[]
 include::separator.adoc[]
+include::adoc/p_Wget.adoc[]
+include::separator.adoc[]
+include::adoc/p_Rget.adoc[]
+include::separator.adoc[]
 include::adoc/p_Cput.adoc[]
 include::separator.adoc[]
+include::adoc/p_Wput.adoc[]
+include::separator.adoc[]
+include::adoc/p_Dput.adoc[]
+include::separator.adoc[]
 include::adoc/p_Rget.adoc[]
 include::separator.adoc[]
 include::adoc/p_Rgt.adoc[]
index 99bac9eb290532001312dcf7fb3db975de493c49..47a6302698178d6aa3ad1d41126d1c99a0475a36 100644 (file)
--- a/stdio.asm
+++ b/stdio.asm
@@ -147,6 +147,27 @@ p_stream_nchars_done:
        popr rsi
        next
 
+;;; ========================================
+;;; Copy line to PAD
+;;; READ-STREAM-LINE ( stream -- n )
+       
+       WORD p_read_stream_line,'READ-STREAM-LINE'
+       ;; ( stream -- n )
+       ;; Read stream until next newline
+       dq p_gtR, p_pad
+p_read_stream_line_loop:
+       dq p_Rget, p_read_stream_char
+       dq p_dup, p_0less
+       BRANCH 1,p_read_stream_line_done
+       dq p_dup, p_nl, p_equal
+       BRANCH 1,p_read_stream_line_done
+       dq p_over, p_Cput, p_literal,1, p_plus
+       BRANCH ,p_read_stream_line_loop
+p_read_stream_line_done:
+       dq p_drop, p_literal,0, p_over, p_Cput
+       dq p_pad, p_minus, p_return
+
+       
 ;;; ========================================
 ;;; Stream reading
 ;;; READ-STREAM-CHAR ( stream -- ch )
index f849eb790574e8664d18fe0f49e2da68c69b7140..5a6aa433b86ad3eb00d1cc4bc3182ef915e4f03d 100644 (file)
@@ -33,12 +33,18 @@ xref:p_get[@] {nbsp}
 xref:p_put[!] {nbsp}
 xref:p_Cget[C@] {nbsp}
 xref:p_Cput[C!] {nbsp}
+xref:p_Wget[W@] {nbsp}
+xref:p_Wput[W!] {nbsp}
+xref:p_Dget[D@] {nbsp}
+xref:p_Dput[D!] {nbsp}
 xref:p_2get[2@] {nbsp}
 xref:p_2put[2!] {nbsp}
 xref:p_put_plus[!{plus}] {nbsp}
 xref:p_get_n_increment[@n{plus}{plus}] {nbsp}
 xref:p_get_n_decrement[@n--] {nbsp}
 xref:p_Ccomma[C,] {nbsp}
+xref:p_Wcomma[W,] {nbsp}
+xref:p_Dcomma[D,] {nbsp}
 xref:p_literal_string_compile[S"] {nbsp}
 xref:p_gtR[>R] {nbsp}
 xref:p_Rget[R@] {nbsp}