summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
Diffstat (limited to 'quine.asm')
-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