summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2025-11-09 14:08:03 -0800
committerIrene Knapp <ireneista@irenes.space>2025-11-09 14:08:03 -0800
commit9368baad9d59f4d00aa11fa1f277be27cf9b412b (patch)
treea7251a077fd26ea79c0d0b3682982fb3f5f6bf40
parentb4a09996fae3047f04e6171e448bbfeecfc27b7d (diff)
implement the rest of the string instructions
in both repeatable and non-repeatable forms

no ins or outs though

Force-Push: yes
Change-Id: Ica93a1de8b3b698db4e9b3c3c2f00b9e145a2064
-rw-r--r--quine.asm131
1 files changed, 115 insertions, 16 deletions
diff --git a/quine.asm b/quine.asm
index 10bb682..7bc78b9 100644
--- a/quine.asm
+++ b/quine.asm
@@ -4026,40 +4026,139 @@ defword push_reg64, 0
 defword pop_reg64, 0
   dq docol, reg64, lit, 0x58, opcodereg, exit
 
-; Stack:
-;   output point
-defword lods64, 0
-  dq docol, rex_w, lit, 0xAD, pack8, exit
+;;;
+;;; String instructions
+;;;
+;;;   What makes these useful is that they take their parameters from certain
+;;; fixed registers, which are chosen such that the operations chain into each
+;;; other well. Thus you can use them to build various block-memory and string
+;;; operations, and even if you need unusual forms of loop unrolling or
+;;; alignment tweaking, the code will end up uniform in structure. On modern
+;;; processors, this is even the high-performance approach, due to highly
+;;; optimized microcode, though these operations were inefficient when they
+;;; were first invented.
+;;;
+;;;   We break with the Intel mnemonics, which follow the pattern
+;;; movsb/movsw/movsd/movsq, because this would otherwise be the only place we
+;;; use the b/w/d/q thing instead of 8/16/32/64. Tradition and
+;;; pronounceability are both nice things, but approachability to newcomers is
+;;; important, too.
+;;;
+;;;   Some of these are repeatable; whether you view the repeatable variants
+;;; as different instructions is up to you. At any rate the machine code
+;;; representation of the repeatable variants is the same as for the regular
+;;; variants with an extra prefix, so we define them together.
 
-;   We break with the Intel mnemonics, which are movsb/movsw/movsd/movsq,
-; because this would otherwise be the only place we use the b/w/d/q thing
-; instead of 8/16/32/64. Tradition and pronounceability are both nice things,
-; but approachability to newcomers is important, too.
-;
 ; Stack:
 ;   output point
+defword movs8, 0
+  dq docol, lit, 0xA4, pack8, exit
+defword movs16, 0
+  dq docol, lit, 0x66, pack8, lit, 0xA5, pack8, exit
+defword movs32, 0
+  dq docol, lit, 0xA5, pack8, exit
+defword movs64, 0
+  dq docol, rex_w, lit, 0xA5, pack8, exit
 defword rep_movs8, 0
   dq docol, lit, 0xF3, pack8, lit, 0xA4, pack8, exit
-
-; Stack:
-;   output point
 defword rep_movs16, 0
   dq docol, lit, 0xF3, pack8, lit, 0x66, pack8, lit, 0xA5, pack8, exit
+defword rep_movs32, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xA5, pack8, exit
+defword rep_movs64, 0
+  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xA5, pack8, exit
 
 ; Stack:
 ;   output point
-defword rep_movs32, 0
-  dq docol, lit, 0xF3, pack8, lit, 0xA5, pack8, exit
+defword lods8, 0
+  dq docol, lit, 0xAC, pack8, exit
+defword lods16, 0
+  dq docol, lit, 0x66, pack8, lit, 0xAD, pack8, exit
+defword lods32, 0
+  dq docol, lit, 0xAD, pack8, exit
+defword lods64, 0
+  dq docol, rex_w, lit, 0xAD, pack8, exit
+defword rep_lods8, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAC, pack8, exit
+defword rep_lods16, 0
+  dq docol, lit, 0xF3, pack8, lit, 0x66, pack8, lit, 0xAD, pack8, exit
+defword rep_lods32, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAD, pack8, exit
+defword rep_lods64, 0
+  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xAD, pack8, exit
+
+; Stack:
+;   output pint
+defword stos8, 0
+  dq docol, lit, 0xAA, pack8, exit
+defword stos16, 0
+  dq docol, lit, 0x66, pack8, lit, 0xAB, pack8, exit
+defword stos32, 0
+  dq docol, lit, 0xAB, pack8, exit
+defword stos64, 0
+  dq docol, rex_w, lit, 0xAB, pack8, exit
+defword rep_stos8, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAA, pack8, exit
+defword rep_stos16, 0
+  dq docol, lit, 0xF3, pack8, lit, 0x66, pack8, lit, 0xAB, pack8, exit
+defword rep_stos32, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAB, pack8, exit
+defword rep_stos64, 0
+  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xAB, pack8, exit
 
 ; Stack:
 ;   output point
-defword rep_movs64, 0
-  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xA5, pack8, exit
+defword cmps8, 0
+  dq docol, lit, 0xA6, pack8, exit
+defword cmps16, 0
+  dq docol, lit, 0x66, pack8, lit, 0xA7, pack8, exit
+defword cmps32, 0
+  dq docol, lit, 0xA7, pack8, exit
+defword cmps64, 0
+  dq docol, rex_w, lit, 0xA7, pack8, exit
+defword repz_cmps8, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xA6, pack8, exit
+defword repz_cmps16, 0
+  dq docol, lit, 0xF3, pack8, lit, 0x66, pack8, lit, 0xA7, pack8, exit
+defword repz_cmps32, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xA7, pack8, exit
+defword repz_cmps64, 0
+  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xA7, pack8, exit
+defword repnz_cmps8, 0
+  dq docol, lit, 0xF2, pack8, lit, 0xA6, pack8, exit
+defword repnz_cmps16, 0
+  dq docol, lit, 0xF2, pack8, lit, 0x66, pack8, lit, 0xA7, pack8, exit
+defword repnz_cmps32, 0
+  dq docol, lit, 0xF2, pack8, lit, 0xA7, pack8, exit
+defword repnz_cmps64, 0
+  dq docol, lit, 0xF2, pack8, rex_w, lit, 0xA7, pack8, exit
 
 ; Stack:
 ;   output point
+defword scas8, 0
+  dq docol, lit, 0xAE, pack8, exit
+defword scas16, 0
+  dq docol, lit, 0x66, pack8, lit, 0xAF, pack8, exit
+defword scas32, 0
+  dq docol, lit, 0xAF, pack8, exit
+defword scas64, 0
+  dq docol, rex_w, lit, 0xAF, pack8, exit
+defword repz_scas8, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAE, pack8, exit
+defword repz_scas16, 0
+  dq docol, lit, 0xF3, pack8, lit, 0x66, pack8, lit, 0xAF, pack8, exit
+defword repz_scas32, 0
+  dq docol, lit, 0xF3, pack8, lit, 0xAF, pack8, exit
+defword repz_scas64, 0
+  dq docol, lit, 0xF3, pack8, rex_w, lit, 0xAF, pack8, exit
 defword repnz_scas8, 0
   dq docol, lit, 0xF2, pack8, lit, 0xAE, pack8, exit
+defword repnz_scas16, 0
+  dq docol, lit, 0xF2, pack8, lit, 0x66, pack8, lit, 0xAF, pack8, exit
+defword repnz_scas32, 0
+  dq docol, lit, 0xF2, pack8, lit, 0xAF, pack8, exit
+defword repnz_scas64, 0
+  dq docol, lit, 0xF2, pack8, rex_w, lit, 0xAF, pack8, exit
 
 ; Stack:
 ;   output point