From: Ralph Ronnquist Date: Sat, 12 Jun 2021 12:48:16 +0000 (+1000) Subject: additional part-cell primitives X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=0a436d5323363af19679ca0a1795b996dc886cfa;p=rrq%2Frrqforth.git additional part-cell primitives --- diff --git a/adoc/p_Dcomma.adoc b/adoc/p_Dcomma.adoc new file mode 100644 index 0000000..db3e821 --- /dev/null +++ b/adoc/p_Dcomma.adoc @@ -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 <> 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 index 0000000..7e68ea0 --- /dev/null +++ b/adoc/p_Dget.adoc @@ -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 index 0000000..5ea8095 --- /dev/null +++ b/adoc/p_Dput.adoc @@ -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 index 0000000..979dcb2 --- /dev/null +++ b/adoc/p_Wcomma.adoc @@ -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 <> 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 index 0000000..9a59576 --- /dev/null +++ b/adoc/p_Wget.adoc @@ -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 index 0000000..3fb2ca8 --- /dev/null +++ b/adoc/p_Wput.adoc @@ -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. + diff --git a/compile.asm b/compile.asm index ff5d853..d99504c 100644 --- a/compile.asm +++ b/compile.asm @@ -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 ;; ( -- ) diff --git a/memory.asm b/memory.asm index 4fe4772..eb84af7 100644 --- a/memory.asm +++ b/memory.asm @@ -83,6 +83,40 @@ 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. diff --git a/reference.adoc b/reference.adoc index 7f1100e..c4b5120 100644 --- a/reference.adoc +++ b/reference.adoc @@ -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[] diff --git a/stdio.asm b/stdio.asm index 99bac9e..47a6302 100644 --- 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 ) diff --git a/wordindex.adoc b/wordindex.adoc index f849eb7..5a6aa43 100644 --- a/wordindex.adoc +++ b/wordindex.adoc @@ -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}