corrected STR>TEMP space allocation
[rrq/rrqforth.git] / logic.asm
1 ;;; Logic words
2
3         WORD p_and, 'AND',fasm
4         ;; ( x1 x2 -- x3 )
5         ;; x3 is the bit-by-bit logical "and" of x1 with x2.
6         pop rax
7         and qword [rsp], rax
8         next
9
10         WORD p_or, 'OR',fasm
11         ;; ( x1 x2 -- x3 )
12         ;; x3 is the bit-by-bit inclusive-or of x1 with x2. 
13         pop rax
14         or qword [rsp],rax
15         next
16
17         WORD p_xor, 'XOR',fasm
18         ;;  ( x1 x2 -- x3 )
19         ;; x3 is the bit-by-bit exclusive-or of x1 with x2.
20         pop rax
21         xor qword [rsp],rax
22         next
23
24         WORD p_not, 'NOT',fasm
25         ;; ( x -- v )
26         ;; v = 0 if x is non-zero and -1 otherwise
27         not qword [rsp]
28         next
29
30         WORD p_false, 'FALSE',dovalue
31         ;; ( -- 0 )
32         ;; Push a false flag, 0.
33         dq 0
34
35         WORD p_true, 'TRUE',dovalue
36         ;; ( -- true )
37         ;; Return a true flag, -1. (non-zero)
38         dq -1
39
40 pop_false_next:
41         mov qword [rsp],0
42         next
43
44 pop_true_next:
45         mov qword [rsp],-1
46         next
47
48         WORD p_within, 'WITHIN',fasm
49         ;; ( n1 n2 n3 -- flag )
50         ;; Push true if n2 <= n1 and n1 < n3 and false otherwise.
51         xor rcx,rcx
52         pop rax
53         pop rbx
54         cmp qword [rsp],rbx
55         jl pop_false_next
56         cmp qword [rsp],rax
57         jge pop_false_next
58         jmp pop_true_next
59
60         WORD p_0less, '0<',fasm
61         ;; ( n -- flag )
62         ;; flag is true (non-zero) if and only if n is less than zero.
63         cmp qword [rsp],0
64         jl pop_true_next
65         jmp pop_false_next
66
67         WORD p_0equal, '0=',fasm
68         ;; ( x -- flag )
69         ;; flag is true if x is equal to zero otherwise false.
70         cmp qword [rsp],0
71         je pop_true_next
72         jmp pop_false_next
73         
74         WORD p_lessthan, '<',fasm
75         ;; ( n1 n2 -- flag )
76         ;; flag is true if and only if n1 is less than n2.
77         pop rax
78         cmp qword [rsp],rax
79         jl pop_true_next
80         jmp pop_false_next
81
82         WORD p_lessequal, '<=',fasm
83         ;; ( n1 n2 -- flag )
84         ;; flag is true if and only if n1 is less than n2.
85         pop rax
86         cmp qword [rsp],rax
87         jle pop_true_next
88         jmp pop_false_next
89
90         WORD p_equal, '=',fasm
91         ;; ( x1 x2 -- flag )
92         ;; flag is true if and only if x1 is bit-for-bit the same as
93         ;; x2.
94         pop rax
95         cmp qword [rsp],rax
96         je pop_true_next
97         jmp pop_false_next
98
99         WORD p_unequal, '!=',fasm
100         ;; ( x1 x2 -- flag )
101         ;; flag is true if and only if x1 is bit-for-bit the same as
102         ;; x2.
103         pop rax
104         cmp qword [rsp],rax
105         jne pop_true_next
106         jmp pop_false_next
107         
108         WORD p_greaterthan, '>',fasm
109         ;; ( n1 n2 -- flag )
110         ;; flag is true if and only if n1 is greater than n2.
111         pop rax
112         cmp qword [rsp],rax
113         jg pop_true_next
114         jmp pop_false_next
115
116         WORD p_greaterequal, '>=',fasm
117         ;; ( n1 n2 -- flag )
118         ;; flag is true if and only if n1 is greater than n2.
119         pop rax
120         cmp qword [rsp],rax
121         jge pop_true_next
122         jmp pop_false_next