From d1df4aca1746f480dca384e63f8bcb4f3ac1d42c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 24 Jan 2018 23:27:45 -0800 Subject: 4197 - done supporting all indirect addressing modes --- subx/014index_addressing.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'subx') diff --git a/subx/014index_addressing.cc b/subx/014index_addressing.cc index 8ab545d3..e811290d 100644 --- a/subx/014index_addressing.cc +++ b/subx/014index_addressing.cc @@ -69,3 +69,47 @@ 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_base_r32_index_r32_plus_disp8) +% Reg[3].i = 0x10; // source +% Reg[0].i = 0x59; // dest base +% Reg[1].i = 0x5; // dest index +% SET_WORD_IN_MEM(0x60, 1); +# op ModR/M SIB displacement immediate + 01 5c 08 02 # add EBX to *(EAX+ECX+2) +# ModR/M in binary: 01 (indirect+disp8 mode) 011 (src EBX) 100 (dest in SIB) +# SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX) ++run: add EBX to r/m32 ++run: effective address is initially 0x59 (EAX) ++run: effective address is 0x5e (after adding ECX*1) ++run: effective address is 0x60 (after adding disp8) ++run: storing 0x00000011 + +:(before "End Mod 1 Special-cases(addr)") +case 4: // exception: mod 0b01 rm 0b100 => incoming SIB (scale-index-base) byte + addr = effective_address_from_sib(mod); + break; + +//: + +:(scenario add_r32_to_mem_at_base_r32_index_r32_plus_disp32) +% Reg[3].i = 0x10; // source +% Reg[0].i = 0x59; // dest base +% Reg[1].i = 0x5; // dest index +% SET_WORD_IN_MEM(0x60, 1); +# op ModR/M SIB displacement immediate + 01 9c 08 02 00 00 00 # add EBX to *(EAX+ECX+2) +# ModR/M in binary: 10 (indirect+disp32 mode) 011 (src EBX) 100 (dest in SIB) +# SIB in binary: 00 (scale 1) 001 (index ECX) 000 (base EAX) ++run: add EBX to r/m32 ++run: effective address is initially 0x59 (EAX) ++run: effective address is 0x5e (after adding ECX*1) ++run: effective address is 0x60 (after adding disp32) ++run: storing 0x00000011 + +:(before "End Mod 2 Special-cases(addr)") +case 4: // exception: mod 0b10 rm 0b100 => incoming SIB (scale-index-base) byte + addr = effective_address_from_sib(mod); + break; -- cgit 1.4.1-2-gfad0