cleanup and add some primitives
[rrq/rrqforth.git] / logic.asm
index a3b183dc097d4edffd9d25233cff77310e4a6245..26963322797442ab1ddbb5a0afd485401b247301 100644 (file)
--- a/logic.asm
+++ b/logic.asm
        push qword -1
        next
 
+pop_false_next:
+       mov qword [rsp],0
+       next
+
+pop_true_next:
+       mov qword [rsp],-1
+       next
+
        WORD p_within, 'WITHIN',fasm
        ;; ( n1 n2 n3 -- flag )
        ;; Push true if n2 <= n1 and n1 < n3 and false otherwise.
@@ -56,57 +64,64 @@ p_within_not:
        WORD p_0less, '0<',fasm
        ;; ( n -- flag )
        ;; flag is true (non-zero) if and only if n is less than zero.
-       xor rax,rax
-       cmp qword [rsp],0
-       jge p_0less.lt
-       not rax
-p_0less.lt:
-       next
+       pop rax
+       cmp rax,qword [rsp]
+       jl pop_true_next
+       jmp pop_false_next
 
        WORD p_0equal, '0=',fasm
        ;; ( x -- flag )
        ;; flag is true if x is equal to zero otherwise false.
-       xor rax,rax
        cmp qword [rsp],0
-       jne p_0equal.ne
-       not rax
-p_0equal.ne:
-       next
+       je pop_true_next
+       jmp pop_false_next
        
        WORD p_lessthan, '<',fasm
        ;; ( n1 n2 -- flag )
        ;; flag is true if and only if n1 is less than n2.
-       xor rax,rax
-       pop rbx
-       cmp qword [rsp], rbx
-       jge p_lessthan.ge
-       not rax
-p_lessthan.ge:
-       mov qword [rsp], rax
-       next
+       pop rax
+       cmp rax,qword [rsp]
+       jl pop_true_next
+       jmp pop_false_next
+
+       WORD p_lessequal, '<=',fasm
+       ;; ( n1 n2 -- flag )
+       ;; flag is true if and only if n1 is less than n2.
+       pop rax
+       cmp rax,qword [rsp]
+       jle pop_true_next
+       jmp pop_false_next
 
        WORD p_equal, '=',fasm
        ;; ( x1 x2 -- flag )
        ;; flag is true if and only if x1 is bit-for-bit the same as
        ;; x2.
-       xor rax,rax
-       pop rbx
-       cmp qword [rsp], rbx
-       jne p_equal.ne
-       not rax
-p_equal.ne:
-       mov qword [rsp], rax
-       next
+       pop rax
+       cmp rax,qword [rsp]
+       je pop_true_next
+       jmp pop_false_next
 
+       WORD p_unequal, '!=',fasm
+       ;; ( x1 x2 -- flag )
+       ;; flag is true if and only if x1 is bit-for-bit the same as
+       ;; x2.
+       pop rax
+       cmp qword [rsp], rax
+       jne pop_true_next
+       jmp pop_false_next
+       
        WORD p_greaterthan, '>',fasm
        ;; ( n1 n2 -- flag )
        ;; flag is true if and only if n1 is greater than n2.
-       xor rax,rax
-       pop rbx
-       cmp qword [rsp], rbx
-       jle p_greaterthan.le
-       not rax
-p_greaterthan.le:
-       mov qword [rsp], rax
-       next
+       pop rax
+       cmp rax,qword [rsp]
+       jg pop_true_next
+       jmp pop_false_next
 
+       WORD p_greaterequal, '>=',fasm
+       ;; ( n1 n2 -- flag )
+       ;; flag is true if and only if n1 is greater than n2.
+       pop rax
+       cmp rax,qword [rsp]
+       jge pop_true_next
+       jmp pop_false_next