summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2025-11-08 17:17:04 -0800
committerIrene Knapp <ireneista@irenes.space>2025-11-08 17:17:04 -0800
commit2d2d48ea91652c254b0e67055c848ceb4ea9bc9c (patch)
treeb2a867da7067fb71065e2d722860cef9209942ad
parent28746ff68d5c35fa3e6b1157e5c473bb2d97a158 (diff)
write comparator words; fix cmp, set, and reg8
Force-Push: yes
Change-Id: I56f82c56307a8e0cd20fdac38dd264136478dd60
-rw-r--r--quine.asm65
1 files changed, 48 insertions, 17 deletions
diff --git a/quine.asm b/quine.asm
index 20a3c23..b67842b 100644
--- a/quine.asm
+++ b/quine.asm
@@ -2125,35 +2125,65 @@ cold_start:
 
   ; This was "eq". Jonesforth calls it "="; most languages would call it "==".
   dq litstring, "=", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_equal, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   ; This was "ne". Jonesforth calls it "<>", but even most modern SQL dialects
   ; recognize C's legacy and allow "!=" these days. As someone who learned C
   ; in childhood, this is not actually a hard call for us.
   dq litstring, "!=", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_not_equal, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   ; This was "gt".
   dq litstring, ">", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_greater, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   ; This was "lt".
   dq litstring, "<", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_less, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   ; This was "ge".
   dq litstring, ">=", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_greater_equal, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   ; This was "le".
   dq litstring, "<=", early_create, early_self_codeword, early_here, fetch
-  ; TODO
-  dq lit, 8, packalign, early_here_store
+  dq rbx, pop_reg64
+  dq rax, pop_reg64
+  dq rbx, rax, cmp_reg64_reg64
+  dq cc_less_equal, al, set_reg8_cc
+  dq lit, 0x01, rax, and_reg64_imm8
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
 
   dq litstring, "and", early_create, early_self_codeword, early_here, fetch
   ; TODO
@@ -3454,6 +3484,7 @@ defword reg16, 0
 ; Stack out:
 ;   3-bit encoded value for register
 defword reg8, 0
+  dq docol
   dq dup, al, eq, zbranch, 5*8, drop, lit, 0, exit
   dq dup, cl, eq, zbranch, 5*8, drop, lit, 1, exit
   dq dup, dl, eq, zbranch, 5*8, drop, lit, 2, exit
@@ -4137,7 +4168,7 @@ defword not_reg64, 0
 ;   right register name
 defword cmp_reg64_reg64, 0
   dq docol
-  dq roll3, rex_w, 0x3B, pack8, unroll3
+  dq roll3, rex_w, lit, 0x3B, pack8, unroll3
   dq swap, reg64, swap, addressing_reg64
   dq exit
 
@@ -4147,18 +4178,18 @@ defword cmp_reg64_reg64, 0
 ;   right register name
 defword test_reg64_reg64, 0
   dq docol
-  dq roll3, rex_w, 0x85, pack8, unroll3
+  dq roll3, rex_w, lit, 0x85, pack8, unroll3
   dq swap, reg64, swap, addressing_reg64
   dq exit
 
 ; Stack:
 ;   output point
-;   target register name
 ;   condition code name
+;   target register name
 defword set_reg8_cc, 0
   dq docol
-  dq unroll3, lit, 0x0F, pack8
-  dq swap, conditioncode, lit, 0x90, opcodecc
+  dq roll3, lit, 0x0F, pack8
+  dq roll3, conditioncode, lit, 0x90, opcodecc
   dq swap, reg8, lit, 3, lit, 0, roll3, modrm
   dq exit