another example
[rrq/rrqforth.git] / stack.asm
index 9726cc2b8eb2883c2e4df7ad4e2a0f7272427b27..637d8aca69da1a778e004f4cee3d4694d089ddaa 100644 (file)
--- a/stack.asm
+++ b/stack.asm
@@ -1,5 +1,23 @@
 ;;; Words for stack manipulations
        
 ;;; Words for stack manipulations
        
+       WORD p_dsp,'D[n]',fasm
+       ;; ( n -- a )
+       ;; Push the address of the n:th cell below n onto the stack
+       pop rax
+       shl rax,3
+       add rax,rsp
+       push rax
+       next
+
+       WORD p_depth,'DEPTH',fasm
+       ;; ( -- v )
+       ;; Push stack depth (before push)
+       lea rax,[DS_TOP]
+       sub rax,rsp
+       shr rax,3
+       push rax
+       next
+
        WORD p_dup, 'DUP',fasm
        ;; ( v -- v v )
        ;; Duplicate top ov stack value.
        WORD p_dup, 'DUP',fasm
        ;; ( v -- v v )
        ;; Duplicate top ov stack value.
@@ -110,12 +128,49 @@ p_roll_eq:
        push qword [rsp+rax]
        next
 
        push qword [rsp+rax]
        next
 
-       WORD w6.2.2300, 'TUCK',fasm
+       WORD p_tuck, 'TUCK',fasm
        ;; ( x1 x2 -- x2 x1 x2 )
        ;; ( x1 x2 -- x2 x1 x2 )
-       ;; insert the top stack value into below second stack value.
+       ;; copy the top stack value into below second stack value.
        pop rax
        pop rbx
        push rax
        push rbx
        push rax
        next
        pop rax
        pop rbx
        push rax
        push rbx
        push rax
        next
+
+;;; ========================================
+;;; Return stack operations
+
+       WORD p_gtR, '>R',fasm
+       ;; ( x -- ) ( R: -- x )
+       ;; Move x to the return stack.
+       pop rax
+       pushr rax
+       next
+
+       WORD p_Rgt, 'R>',fasm
+       ;; ( -- x ) ( R: x -- )
+       ;; Move x from the return stack to the data stack.
+       popr rax
+       push rax
+       next
+
+       WORD p_Rget, 'R@',fasm
+       ;; ( -- x ) ( R: x -- x )
+       ;; Copy x from the return stack to the data stack.
+       push qword [rbp]
+       next
+
+       WORD p_rbp,'RSP',fasm
+       ;; Push the return stack pointer to the data stack
+       push rbp
+       next
+       
+       WORD p_rbpn,'R[n]',fasm
+       ;; ( n -- a )
+       ;; push the address of the n:th cell on the return stack
+       mov rax,qword [rsp]
+       shl rax,3
+       add rax,rbp
+       mov qword [rsp],rax
+       next