From 3639efce2021fce6c49f34ce90a6f84fbe6f8fa6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 24 Jan 2018 21:34:25 -0800 Subject: 4193 --- subx/012indirect_addressing.cc | 20 ++++++++++++++++++++ subx/014index_addressing.cc | 24 ------------------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/subx/012indirect_addressing.cc b/subx/012indirect_addressing.cc index 579c5255..a01b03f8 100644 --- a/subx/012indirect_addressing.cc +++ b/subx/012indirect_addressing.cc @@ -408,3 +408,23 @@ case 0x8f: { // pop stack into r/m32 } break; } + +//:: special-case for loading address from disp32 rather than register + +:(scenario add_r32_to_mem_at_displacement) +% Reg[3].i = 0x10; // source +% SET_WORD_IN_MEM(0x60, 1); +# op ModR/M SIB displacement immediate + 01 1d 60 00 00 00 # add EBX to *0x60 +# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 101 (dest in disp32) ++run: add EBX to r/m32 ++run: effective address is 0x60 (disp32) ++run: storing 0x00000011 + +:(before "End Mod 0 Special-cases") +case 5: { // exception: mod 0b00 rm 0b101 => incoming disp32 + uint32_t addr = imm32(); + result = reinterpret_cast(&Mem.at(addr)); + trace(2, "run") << "effective address is 0x" << std::hex << addr << " (disp32)" << end(); + break; +} diff --git a/subx/014index_addressing.cc b/subx/014index_addressing.cc index 4788216b..9e432863 100644 --- a/subx/014index_addressing.cc +++ b/subx/014index_addressing.cc @@ -63,8 +63,6 @@ uint32_t effective_address_from_sib(uint8_t mod) { :(scenario add_r32_to_mem_at_displacement_using_sib) % Reg[3].i = 0x10; // source -% Reg[0].i = 0x5e; // dest base -% Reg[1].i = 0x2; // dest index % SET_WORD_IN_MEM(0x60, 1); # op ModR/M SIB displacement immediate 01 1c 25 60 00 00 00 # add EBX to *0x60 @@ -74,25 +72,3 @@ uint32_t effective_address_from_sib(uint8_t mod) { +run: effective address is initially 0x60 (disp32) +run: effective address is 0x60 +run: storing 0x00000011 - -//: - -:(scenario add_r32_to_mem_at_displacement) -% Reg[3].i = 0x10; // source -% Reg[0].i = 0x5e; // dest base -% Reg[1].i = 0x2; // dest index -% SET_WORD_IN_MEM(0x60, 1); -# op ModR/M SIB displacement immediate - 01 1d 60 00 00 00 # add EBX to *0x60 -# ModR/M in binary: 00 (indirect mode) 011 (src EBX) 101 (dest in disp32) -+run: add EBX to r/m32 -+run: effective address is 0x60 (disp32) -+run: storing 0x00000011 - -:(before "End Mod 0 Special-cases") -case 5: { // exception: mod 0b00 rm 0b101 => incoming disp32 - uint32_t addr = imm32(); - result = reinterpret_cast(&Mem.at(addr)); - trace(2, "run") << "effective address is 0x" << std::hex << addr << " (disp32)" << end(); - break; -} -- cgit 1.4.1-2-gfad0