From bc9f26de6737e762e5e6045fc874d68842e98bca Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 24 Jan 2018 22:58:30 -0800 Subject: 4196 --- subx/012indirect_addressing.cc | 46 +++++++++++++++++++++++++----------------- subx/014index_addressing.cc | 2 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/subx/012indirect_addressing.cc b/subx/012indirect_addressing.cc index ed478632..18ca6b5f 100644 --- a/subx/012indirect_addressing.cc +++ b/subx/012indirect_addressing.cc @@ -420,7 +420,7 @@ case 0x8f: { // pop stack into r/m32 +run: effective address is 0x60 (disp32) +run: storing 0x00000011 -:(before "End Mod 0 Special-cases") +:(before "End Mod 0 Special-cases(addr)") case 5: // exception: mod 0b00 rm 0b101 => incoming disp32 addr = imm32(); trace(2, "run") << "effective address is 0x" << std::hex << addr << " (disp32)" << end(); @@ -436,19 +436,22 @@ case 5: // exception: mod 0b00 rm 0b101 => incoming disp32 01 58 02 # add EBX to *(EAX+2) # ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 000 (dest EAX) +run: add EBX to r/m32 -+run: effective address is 0x60 (EAX+disp8) ++run: effective address is initially 0x5e (EAX) ++run: effective address is 0x60 (after adding disp8) +run: storing 0x00000011 :(before "End Mod Special-cases(addr)") case 1: // indirect + disp8 addressing switch (rm) { - default: { - int8_t disp = next(); - addr = Reg[rm].u + disp; - trace(2, "run") << "effective address is 0x" << std::hex << addr << " (" << rname(rm) << "+disp8)" << end(); - break; - } - // End Mod 1 Special-cases(addr) + default: + addr = Reg[rm].u; + trace(2, "run") << "effective address is initially 0x" << std::hex << addr << " (" << rname(rm) << ")" << end(); + break; + // End Mod 1 Special-cases(addr) + } + if (addr > 0) { + addr += static_cast(next()); + trace(2, "run") << "effective address is 0x" << std::hex << addr << " (after adding disp8)" << end(); } break; @@ -460,7 +463,8 @@ case 1: // indirect + disp8 addressing 01 58 ff # add EBX to *(EAX-1) # ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 000 (dest EAX) +run: add EBX to r/m32 -+run: effective address is 0x60 (EAX+disp8) ++run: effective address is initially 0x61 (EAX) ++run: effective address is 0x60 (after adding disp8) +run: storing 0x00000011 //: @@ -473,19 +477,22 @@ case 1: // indirect + disp8 addressing 01 98 02 00 00 00 # add EBX to *(EAX+2) # ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 000 (dest EAX) +run: add EBX to r/m32 -+run: effective address is 0x60 (EAX+disp32) ++run: effective address is initially 0x5e (EAX) ++run: effective address is 0x60 (after adding disp32) +run: storing 0x00000011 :(before "End Mod Special-cases(addr)") case 2: // indirect + disp32 addressing switch (rm) { - default: { - int32_t disp = imm32(); - addr = Reg[rm].u + disp; - trace(2, "run") << "effective address is 0x" << std::hex << addr << " (" << rname(rm) << "+disp32)" << end(); - break; - } - // End Mod 2 Special-cases(addr) + default: + addr = Reg[rm].u; + trace(2, "run") << "effective address is initially 0x" << std::hex << addr << " (" << rname(rm) << ")" << end(); + break; + // End Mod 2 Special-cases(addr) + } + if (addr > 0) { + addr += imm32(); + trace(2, "run") << "effective address is 0x" << std::hex << addr << " (after adding disp32)" << end(); } break; @@ -497,5 +504,6 @@ case 2: // indirect + disp32 addressing 01 98 ff ff ff ff # add EBX to *(EAX-1) # ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 000 (dest EAX) +run: add EBX to r/m32 -+run: effective address is 0x60 (EAX+disp32) ++run: effective address is initially 0x61 (EAX) ++run: effective address is 0x60 (after adding disp32) +run: storing 0x00000011 diff --git a/subx/014index_addressing.cc b/subx/014index_addressing.cc index 37a4b9be..8ab545d3 100644 --- a/subx/014index_addressing.cc +++ b/subx/014index_addressing.cc @@ -13,7 +13,7 @@ +run: effective address is 0x60 +run: storing 0x00000011 -:(before "End Mod 0 Special-cases") +:(before "End Mod 0 Special-cases(addr)") case 4: // exception: mod 0b00 rm 0b100 => incoming SIB (scale-index-base) byte addr = effective_address_from_sib(mod); break; -- cgit 1.4.1-2-gfad0 'n44' href='#n44'>44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155