reworked word lists
[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',fasm
31         ;; ( -- 0 )
32         ;; Push a false flag, 0.
33         push qword 0
34         next
35
36         WORD p_true, 'TRUE',fasm
37         ;; ( -- true )
38         ;; Return a true flag, -1. (non-zero)
39         push qword -1
40         next
41
42         WORD p_within, 'WITHIN',fasm
43         ;; ( n1 n2 n3 -- flag )
44         ;; Push true if n2 <= n1 and n1 < n3 and false otherwise.
45         xor rcx,rcx
46         pop rax
47         pop rbx
48         cmp qword [rsp],rbx
49         jl p_within_not
50         cmp qword [rsp],rax
51         jge p_within_not
52         not rcx
53 p_within_not:
54         next
55         
56         WORD p_0less, '0<',fasm
57         ;; ( n -- flag )
58         ;; flag is true (non-zero) if and only if n is less than zero.
59         xor rax,rax
60         cmp qword [rsp],0
61         jge p_0less.lt
62         not rax
63 p_0less.lt:
64         next
65
66         WORD p_0equal, '0=',fasm
67         ;; ( x -- flag )
68         ;; flag is true if x is equal to zero otherwise false.
69         xor rax,rax
70         cmp qword [rsp],0
71         jne p_0equal.ne
72         not rax
73 p_0equal.ne:
74         next
75         
76         WORD p_lessthan, '<',fasm
77         ;; ( n1 n2 -- flag )
78         ;; flag is true if and only if n1 is less than n2.
79         xor rax,rax
80         pop rbx
81         cmp qword [rsp], rbx
82         jge p_lessthan.ge
83         not rax
84 p_lessthan.ge:
85         mov qword [rsp], rax
86         next
87
88         WORD p_equal, '=',fasm
89         ;; ( x1 x2 -- flag )
90         ;; flag is true if and only if x1 is bit-for-bit the same as
91         ;; x2.
92         xor rax,rax
93         pop rbx
94         cmp qword [rsp], rbx
95         jne p_equal.ne
96         not rax
97 p_equal.ne:
98         mov qword [rsp], rax
99         next
100
101         WORD p_greaterthan, '>',fasm
102         ;; ( n1 n2 -- flag )
103         ;; flag is true if and only if n1 is greater than n2.
104         xor rax,rax
105         pop rbx
106         cmp qword [rsp], rbx
107         jle p_greaterthan.le
108         not rax
109 p_greaterthan.le:
110         mov qword [rsp], rax
111         next
112