summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-04-08 21:14:20 -0700
committerIrene Knapp <ireneista@irenes.space>2026-04-08 21:15:19 -0700
commit88d0db591d2d9f6014fa98a9007dc5d05b4bb114 (patch)
tree7a5257ef516f45963a9e4beaf093e6c8a8c258ff /quine.asm
parentef12766fe71d222557b6be277898c60c69f0f108 (diff)
add heap implementations for more assembly string ops
also add Forth words for a couple missing assembly instructions

the map is kept carefully up-to-date through this, and the binary output of the new implementations was checked against the binary output of the original implementations using the new dictionary-debugging feature

Force-Push: yes
Change-Id: Icc8666dc0da9697ccab5d235b714efaa9bdba113
Diffstat (limited to 'quine.asm')
-rw-r--r--quine.asm58
1 files changed, 56 insertions, 2 deletions
diff --git a/quine.asm b/quine.asm
index ba1c7c4..cc75f6b 100644
--- a/quine.asm
+++ b/quine.asm
@@ -2460,6 +2460,37 @@ cold_start:
   dq rdi, push_reg64
   dq pack_next, lit, 8, packalign, early_here_store
 
+  ; This was "reverse_stringlen".
+  dq litstring, "reverse-stringlen", early_create, early_self_codeword
+  dq early_here, fetch
+  dq rdi, pop_reg64
+  dq rdi, rbx, mov_reg64_reg64
+  dq rax, rax, xor_reg64_reg64
+  dq rcx, rcx, xor_reg64_reg64
+  dq rcx, not_reg64
+  dq std
+  dq repnz_scas8
+  dq cld
+  dq rbx, rdi, sub_reg64_reg64
+  dq lit, 1, rbx, sub_reg64_imm8
+  dq rbx, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
+
+  ; This was "reverse_padding_len".
+  dq litstring, "reverse-padding-len", early_create, early_self_codeword
+  dq early_here, fetch
+  dq rdi, pop_reg64
+  dq rdi, rbx, mov_reg64_reg64
+  dq rax, rax, xor_reg64_reg64
+  dq lit, 9, rcx, mov_reg64_imm32
+  dq std
+  dq repz_scas8
+  dq cld
+  dq rbx, rdi, sub_reg64_reg64
+  dq lit, 1, rbx, sub_reg64_imm8
+  dq rbx, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
+
   dq litstring, "branch", early_create, early_self_codeword, early_here, fetch
   ; Save the address we're packing to; it will be the label we jump to from
   ; zbranch.
@@ -2691,7 +2722,6 @@ cold_start:
   ;;;   addstore, substore, store8, fetch8, store16, fetch16, store32, fetch32
   ;;;   memcopy, stringlen
   ;;;   reverse_stringlen, reverse_padding_len
-  ;;;     TODO needs heap impl
   ;;;   stringcmp
   ;;;     TODO needs heap impl
   ;;;     no dependencies except next for any of these
@@ -2737,7 +2767,9 @@ cold_start:
   ;;;   addressing_reg64, addressing_indirect_reg64, addressing_disp8_reg64,
   ;;;   addressing_indexed_reg64, addressing_disp8_indexed_reg64
   ;;;     basics plus earlier assembly stuff
-  ;;;   cld, std, mov_reg64_imm64, mov_extrareg64_imm64, mov_reg64_reg64,
+  ;;;   cld, std,
+  ;;;   mov_reg64_imm32, mov_reg64_imm64,
+  ;;;   mov_extrareg64_imm64, mov_reg64_reg64,
   ;;;   mov_indirect_reg64_reg64, mov_disp8_reg64_reg64,
   ;;;   mov_reg64_indirect_reg64, mov_reg64_disp8_reg64,
   ;;;   mov_reg64_indexed_reg64, mov_indexed_reg64_reg64,
@@ -2765,6 +2797,7 @@ cold_start:
   ;;;   add_reg64_reg64, add_indirect_reg64_reg64, add_reg64_indirect_reg64,
   ;;;   add_reg64_imm8,
   ;;;   sub_reg64_reg64, sub_indirect_reg64_reg64,
+  ;;;   sub_reg64_imm8,
   ;;;   mul_reg64, divmod_reg64, idivmod_reg64, inc_reg64, dec_reg64,
   ;;;   and_reg64_reg64, and_reg64_imm8,
   ;;;   or_reg64_reg64, or_reg64_imm8,
@@ -4525,6 +4558,17 @@ defword std, 0
 ;   output point
 ;   immediate value
 ;   register name
+defword mov_reg64_imm32, 0
+  dq docol
+  dq roll3, rex_w, lit, 0xC7, pack8, swap
+  dq lit, 0, swap, addressing_reg64
+  dq swap, pack32
+  dq exit
+
+; Stack:
+;   output point
+;   immediate value
+;   register name
 defword mov_reg64_imm64, 0
   dq docol
   dq roll3, rex_w, swap, reg64, lit, 0xB8, opcodereg, swap, pack64
@@ -4984,6 +5028,16 @@ defword sub_indirect_reg64_reg64, 0
   dq swap, reg64, swap, addressing_indirect_reg64
   dq exit
 
+; Stack:
+;   output point
+;   source value
+;   target register name
+defword sub_reg64_imm8, 0
+  dq docol
+  dq roll3, rex_w, lit, 0x83, pack8, swap, lit, 5, swap, addressing_reg64
+  dq swap, pack8
+  dq exit
+
 ;   The target register is always rax.
 ;
 ; Stack: