about summary refs log tree commit diff stats
path: root/subx/014index_addressing.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2018-01-24 19:27:13 -0800
committerKartik K. Agaram <vc@akkartik.com>2018-01-24 19:27:13 -0800
commit070b4642fc7330745bb5f023be948e3ad479069c (patch)
tree97b42ce7b364f09adc624e767a761ea8122843fc /subx/014index_addressing.cc
parent4e8041619808c860d41b3de135db7de90e153493 (diff)
downloadmu-070b4642fc7330745bb5f023be948e3ad479069c.tar.gz
4187
Diffstat (limited to 'subx/014index_addressing.cc')
-rw-r--r--subx/014index_addressing.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/subx/014index_addressing.cc b/subx/014index_addressing.cc
index 4deff72a..826a488f 100644
--- a/subx/014index_addressing.cc
+++ b/subx/014index_addressing.cc
@@ -6,7 +6,7 @@
 % SET_WORD_IN_MEM(0x60, 1);
 # op  ModR/M  SIB   displacement  immediate
   01  1c      20                             # add EBX to *EAX
-# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)
+# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 100 (dest in SIB)
 # SIB in binary: 00 (scale 1) 100 (no index) 000 (base EAX)
 +run: add EBX to effective address
 +run: effective address is mem at address 0x60 (EAX)
@@ -21,16 +21,18 @@ case 4:  // exception: mod 0b00 rm 0b100 => incoming SIB (scale-index-base) byte
     // of EBP. This gets complicated, and I don't understand interactions with
     // displacement mode in Mod/RM. For example:
     //
-    // op (hex)   ModR/M (binary)                     SIB (binary)                                      displacement (hex)
-    // 0x01       01 100 /*SIB+disp8*/ 000 /*EAX*/    00 /*scale*/ 100 /*no index*/ 101 /*EBP+disp8*/   0xf0
+    // op (hex)   ModR/M (binary)                                  SIB (binary)                                      displacement (hex)
+    // 0x01       01 /*indirect+disp8*/ 000 /*EAX*/ 100 /*SIB*/    00 /*scale*/ 100 /*no index*/ 101 /*EBP+disp8*/   0xf0
     //
-    // Do the two disp8's accumulate (so the instruction has *two* disp8's)?
-    // multiply? cancel out?!
+    // Do the two displacements accumulate (so the instruction has *two*
+    // displacement fields)?
     //
-    // Maybe this is the answer:
+    // Maybe they're redundant:
     //   "When the ModR/M or SIB tables state that a disp value is required..
     //   then the displacement bytes are required."
     //   -- https://wiki.osdev.org/X86-64_Instruction_Encoding#Displacement
+    //
+    // That's the only option that makes sense for 32-bit displacement (mod 10)
     raise << "base 5 (often but not always EBP) not supported in SIB byte\n" << end();
     break;
   }
@@ -55,7 +57,7 @@ case 4:  // exception: mod 0b00 rm 0b100 => incoming SIB (scale-index-base) byte
 % SET_WORD_IN_MEM(0x60, 1);
 # op  ModR/M  SIB   displacement  immediate
   01  1c      08                             # add EBX to *(EAX+ECX)
-# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX)
+# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 100 (dest in SIB)
 # SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX)
 +run: add EBX to effective address
 +run: effective address is mem at address 0x60 (EAX + ECX*1)