From bcb53ba8222ecba94f82880c98a23f2fc8a66161 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Sat, 22 May 2021 21:34:06 +1000 Subject: [PATCH] cleanup and add some primitives --- logic.asm | 85 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/logic.asm b/logic.asm index a3b183d..2696332 100644 --- a/logic.asm +++ b/logic.asm @@ -39,6 +39,14 @@ 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 -- 2.39.2