diff options
Diffstat (limited to 'subx/014indirect_addressing.cc')
-rw-r--r-- | subx/014indirect_addressing.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/subx/014indirect_addressing.cc b/subx/014indirect_addressing.cc index 9142728a..ccbf994c 100644 --- a/subx/014indirect_addressing.cc +++ b/subx/014indirect_addressing.cc @@ -388,16 +388,18 @@ case 0x8b: { // copy r32 to r/m32 put(name, "88", "copy r8 (lowermost byte of r32) to r8/m8-at-r32"); :(scenario copy_r8_to_mem_at_r32) -% Reg[EBX].i = 0xafafafaf; +% Reg[EBX].i = 0x224488ab; % Reg[EAX].i = 0x60; == 0x1 # op ModR/M SIB displacement immediate 88 18 # copy just the lowermost byte of EBX to the byte at *EAX # ModR/M in binary: 00 (indirect mode) 011 (src EBX) 000 (dest EAX) +== 0x60 +f0 cc bb aa # 0xf0 with more data in following bytes +run: copy lowermost byte of EBX to r8/m8-at-r32 +run: effective address is 0x60 (EAX) -+run: storing 0xaf -% CHECK_EQ(0x000000af, read_mem_u32(0x60)); ++run: storing 0xab +% CHECK_EQ(0xaabbccab, read_mem_u32(0x60)); :(before "End Single-Byte Opcodes") case 0x88: { // copy r/m8 to r8 @@ -417,17 +419,19 @@ case 0x88: { // copy r/m8 to r8 put(name, "8a", "copy r8/m8-at-r32 to r8 (lowermost byte of r32)"); :(scenario copy_mem_at_r32_to_r8) -% Reg[EBX].i = 0xaf; +% Reg[EBX].i = 0xaabbcc0f; // one nibble each of lowest byte set to all 0s and all 1s, to maximize value of this test % Reg[EAX].i = 0x60; == 0x1 # op ModR/M SIB displacement immediate 8a 18 # copy just the byte at *EAX to lowermost byte of EBX (clearing remaining bytes) # ModR/M in binary: 00 (indirect mode) 011 (dest EBX) 000 (src EAX) == 0x60 # data segment -af ff ff ff # 0xaf with more data in following bytes +ab ff ff ff # 0xab with more data in following bytes +run: copy r8/m8-at-r32 to lowermost byte of EBX +run: effective address is 0x60 (EAX) -+run: storing 0xaf ++run: storing 0xab +# remaining bytes of EBX are *not* cleared ++run: EBX now contains 0xaabbccab :(before "End Single-Byte Opcodes") case 0x8a: { // copy r/m8 to r8 @@ -436,8 +440,9 @@ case 0x8a: { // copy r/m8 to r8 trace(90, "run") << "copy r8/m8-at-r32 to lowermost byte of " << rname(reg1) << end(); // use unsigned to zero-extend 8-bit value to 32 bits uint8_t* arg2 = reinterpret_cast<uint8_t*>(effective_address(modrm)); - Reg[reg1].u = static_cast<uint32_t>(*arg2); trace(90, "run") << "storing 0x" << HEXBYTE << NUM(*arg2) << end(); + *reinterpret_cast<uint8_t*>(&Reg[reg1].u) = *arg2; // assumes host is little-endian + trace(90, "run") << rname(reg1) << " now contains 0x" << HEXWORD << Reg[reg1].u << end(); break; } |