diff options
-rw-r--r-- | subx/011run.cc | 4 | ||||
-rw-r--r-- | subx/014indirect_addressing.cc | 76 | ||||
-rw-r--r-- | subx/015immediate_addressing.cc | 18 | ||||
-rw-r--r-- | subx/016index_addressing.cc | 32 | ||||
-rw-r--r-- | subx/019functions.cc | 2 | ||||
-rw-r--r-- | subx/021byte_addressing.cc | 4 |
6 files changed, 68 insertions, 68 deletions
diff --git a/subx/011run.cc b/subx/011run.cc index b1ff46dd..61d93186 100644 --- a/subx/011run.cc +++ b/subx/011run.cc @@ -201,7 +201,7 @@ void parse_word(const string& data, word& out) { void sanity_check_program_segment(const program& p, uint32_t addr) { for (int i = 0; i < SIZE(p.segments); ++i) { if (p.segments.at(i).start == addr) - raise << "can't have multiple segments starting at address 0x" << std::hex << addr << '\n' << end(); + raise << "can't have multiple segments starting at address 0x" << HEXWORD << addr << '\n' << end(); } } @@ -219,7 +219,7 @@ void parse(const string& text_bytes) { ab == 0xee cd -+error: can't have multiple segments starting at address 0xee ++error: can't have multiple segments starting at address 0x000000ee //:: transform diff --git a/subx/014indirect_addressing.cc b/subx/014indirect_addressing.cc index c415c96c..e00cb1d5 100644 --- a/subx/014indirect_addressing.cc +++ b/subx/014indirect_addressing.cc @@ -11,14 +11,14 @@ == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x00000011 :(before "End Mod Special-cases(addr)") case 0: // indirect addressing switch (rm) { default: // address in register - trace(90, "run") << "effective address is 0x" << std::hex << Reg[rm].u << " (" << rname(rm) << ")" << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << Reg[rm].u << " (" << rname(rm) << ")" << end(); addr = Reg[rm].u; break; // End Mod 0 Special-cases(addr) @@ -40,7 +40,7 @@ put_new(Name, "03", "add rm32 to r32 (add)"); == 0x2000 # data segment 01 00 00 00 # 1 +run: add r/m32 to EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x00000011 :(before "End Single-Byte Opcodes") @@ -65,7 +65,7 @@ case 0x03: { // add r/m32 to r32 == 0x2000 # data segment 0a 00 00 00 # 10 +run: subtract EBX from r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x00000009 //: @@ -83,7 +83,7 @@ put_new(Name, "2b", "subtract rm32 from r32 (sub)"); == 0x2000 # data segment 01 00 00 00 # 1 +run: subtract r/m32 from EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x00000009 :(before "End Single-Byte Opcodes") @@ -108,7 +108,7 @@ case 0x2b: { // subtract r/m32 from r32 == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: and EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x0000000d //: @@ -126,7 +126,7 @@ put_new(Name, "23", "r32 = bitwise AND of r32 with rm32 (and)"); == 0x2000 # data segment ff 00 00 00 # 0xff +run: and r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x0000000d :(before "End Single-Byte Opcodes") @@ -151,7 +151,7 @@ case 0x23: { // and r/m32 with r32 == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: or EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0xaabbccdd //: @@ -169,7 +169,7 @@ put_new(Name, "0b", "r32 = bitwise OR of r32 with rm32 (or)"); == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: or r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0xaabbccdd :(before "End Single-Byte Opcodes") @@ -194,7 +194,7 @@ case 0x0b: { // or r/m32 with r32 == 0x2000 # data segment 0d 0c bb aa # 0xaabb0c0d +run: xor EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x0a0bccdd //: @@ -212,7 +212,7 @@ put_new(Name, "33", "r32 = bitwise XOR of r32 with rm32 (xor)"); == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: xor r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0xaabbccdd :(before "End Single-Byte Opcodes") @@ -236,7 +236,7 @@ case 0x33: { // xor r/m32 with r32 == 0x2000 # data segment ff 00 0f 0f # 0x0f0f00ff +run: operate on r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: subop: not +run: storing 0xf0f0ff00 @@ -252,7 +252,7 @@ ff 00 0f 0f # 0x0f0f00ff == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: compare EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=0; ZF=0; OF=0 :(scenario compare_mem_at_r32_with_r32_lesser) @@ -265,7 +265,7 @@ ff 00 0f 0f # 0x0f0f00ff == 0x2000 # data segment 07 0c 0b 0a # 0x0a0b0c0d +run: compare EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=1; ZF=0; OF=0 :(scenario compare_mem_at_r32_with_r32_equal) @@ -278,7 +278,7 @@ ff 00 0f 0f # 0x0f0f00ff == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: compare EBX with r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=0; ZF=1; OF=0 //: @@ -296,7 +296,7 @@ put_new(Name, "3b", "compare: set SF if r32 < rm32 (cmp)"); == 0x2000 # data segment 07 0c 0b 0a # 0x0a0b0c0d +run: compare r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=0; ZF=0; OF=0 :(before "End Single-Byte Opcodes") @@ -325,7 +325,7 @@ case 0x3b: { // set SF if r32 < r/m32 == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: compare r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=1; ZF=0; OF=0 :(scenario compare_r32_with_mem_at_r32_equal) @@ -338,7 +338,7 @@ case 0x3b: { // set SF if r32 < r/m32 == 0x2000 # data segment 0d 0c 0b 0a # 0x0a0b0c0d +run: compare r/m32 with EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: SF=0; ZF=1; OF=0 //:: copy (mov) @@ -351,7 +351,7 @@ case 0x3b: { // set SF if r32 < r/m32 89 18 # copy EBX to *EAX # ModR/M in binary: 00 (indirect mode) 011 (src EAX) 000 (dest EAX) +run: copy EBX to r/m32 -+run: effective address is 0x60 (EAX) ++run: effective address is 0x00000060 (EAX) +run: storing 0x000000af //: @@ -368,7 +368,7 @@ put_new(Name, "8b", "copy rm32 to r32 (mov)"); == 0x2000 # data segment af 00 00 00 # 0xaf +run: copy r/m32 to EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0x000000af :(before "End Single-Byte Opcodes") @@ -396,7 +396,7 @@ case 0x8b: { // copy r32 to r/m32 08 00 00 00 # 8 +run: inst: 0x00000001 +run: jump to r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: jumping to 0x00000008 +run: inst: 0x00000008 -run: inst: 0x00000003 @@ -422,7 +422,7 @@ case 4: { // jump to r/m32 == 0x2000 # data segment af 00 00 00 # 0xaf +run: push r/m32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: decrementing ESP to 0x00000010 +run: pushing value 0x000000af @@ -449,7 +449,7 @@ put_new(Name, "8f", "pop top of stack to rm32 (pop)"); == 0x2000 # data segment 30 00 00 00 # 0x30 +run: pop into r/m32 -+run: effective address is 0x60 (EAX) ++run: effective address is 0x00000060 (EAX) +run: popping value 0x00000030 +run: incrementing ESP to 0x00002004 @@ -479,13 +479,13 @@ case 0x8f: { // pop stack into r/m32 == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is 0x2000 (disp32) ++run: effective address is 0x00002000 (disp32) +run: storing 0x00000011 :(before "End Mod 0 Special-cases(addr)") case 5: // exception: mod 0b00 rm 0b101 => incoming disp32 addr = next32(); - trace(90, "run") << "effective address is 0x" << std::hex << addr << " (disp32)" << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << addr << " (disp32)" << end(); break; //: @@ -500,8 +500,8 @@ case 5: // exception: mod 0b00 rm 0b101 => incoming disp32 == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x1ffe (EAX) -+run: effective address is 0x2000 (after adding disp8) ++run: effective address is initially 0x00001ffe (EAX) ++run: effective address is 0x00002000 (after adding disp8) +run: storing 0x00000011 :(before "End Mod Special-cases(addr)") @@ -509,13 +509,13 @@ case 1: // indirect + disp8 addressing switch (rm) { default: addr = Reg[rm].u; - trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (" << rname(rm) << ")" << end(); + trace(90, "run") << "effective address is initially 0x" << HEXWORD << addr << " (" << rname(rm) << ")" << end(); break; // End Mod 1 Special-cases(addr) } if (addr > 0) { addr += static_cast<int8_t>(next()); - trace(90, "run") << "effective address is 0x" << std::hex << addr << " (after adding disp8)" << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding disp8)" << end(); } break; @@ -529,8 +529,8 @@ case 1: // indirect + disp8 addressing == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x2001 (EAX) -+run: effective address is 0x2000 (after adding disp8) ++run: effective address is initially 0x00002001 (EAX) ++run: effective address is 0x00002000 (after adding disp8) +run: storing 0x00000011 //: @@ -545,8 +545,8 @@ case 1: // indirect + disp8 addressing == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x1ffe (EAX) -+run: effective address is 0x2000 (after adding disp32) ++run: effective address is initially 0x00001ffe (EAX) ++run: effective address is 0x00002000 (after adding disp32) +run: storing 0x00000011 :(before "End Mod Special-cases(addr)") @@ -554,13 +554,13 @@ case 2: // indirect + disp32 addressing switch (rm) { default: addr = Reg[rm].u; - trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (" << rname(rm) << ")" << end(); + trace(90, "run") << "effective address is initially 0x" << HEXWORD << addr << " (" << rname(rm) << ")" << end(); break; // End Mod 2 Special-cases(addr) } if (addr > 0) { addr += next32(); - trace(90, "run") << "effective address is 0x" << std::hex << addr << " (after adding disp32)" << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding disp32)" << end(); } break; @@ -574,8 +574,8 @@ case 2: // indirect + disp32 addressing == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x2001 (EAX) -+run: effective address is 0x2000 (after adding disp32) ++run: effective address is initially 0x00002001 (EAX) ++run: effective address is 0x00002000 (after adding disp32) +run: storing 0x00000011 //:: lea @@ -590,7 +590,7 @@ put_new(Name, "8d", "copy address in rm32 into r32 (lea)"); 8d 18 # ModR/M in binary: 00 (indirect mode) 011 (dest EBX) 000 (src EAX) +run: lea into EBX -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) :(before "End Single-Byte Opcodes") case 0x8d: { // lea m32 to r32 diff --git a/subx/015immediate_addressing.cc b/subx/015immediate_addressing.cc index e10c5ac7..a5d385b7 100644 --- a/subx/015immediate_addressing.cc +++ b/subx/015immediate_addressing.cc @@ -47,7 +47,7 @@ case 0x81: { // combine imm32 with r/m32 == 0x2000 # data segment 01 00 00 00 # 1 +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: subop add +run: storing 0x0d0c0b0b @@ -84,7 +84,7 @@ case 0x2d: { // subtract imm32 from EAX == 0x2000 # data segment 0a 00 00 00 # 10 +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x00000001 +run: subop subtract +run: storing 0x00000009 @@ -142,7 +142,7 @@ case 0x25: { // and imm32 with EAX == 0x2000 # data segment ff 00 00 00 # 0xff +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: subop and +run: storing 0x0000000a @@ -200,7 +200,7 @@ case 0x0d: { // or imm32 with EAX == 0x2000 # data segment a0 b0 c0 d0 # 0xd0c0b0a0 +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: subop or +run: storing 0xddccbbaa @@ -256,7 +256,7 @@ case 0x35: { // xor imm32 with EAX == 0x2000 # data segment a0 b0 c0 d0 # 0xd0c0b0a0 +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: subop xor +run: storing 0xddccbbaa @@ -379,7 +379,7 @@ case 7: { == 0x2000 # data segment 0a 0b 0c 0d # 0x0d0c0b0a +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b07 +run: SF=0; ZF=0; OF=0 @@ -392,7 +392,7 @@ case 7: { == 0x2000 # data segment 07 0b 0c 0d # 0x0d0c0b07 +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: SF=1; ZF=0; OF=0 @@ -406,7 +406,7 @@ case 7: { == 0x2000 # data segment 0a 0b 0c 0d # 0x0d0c0b0a +run: combine imm32 with r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: imm32 is 0x0d0c0b0a +run: SF=0; ZF=1; OF=0 @@ -456,7 +456,7 @@ put_new(Name, "c7", "copy imm32 to rm32 (mov)"); c7 03 0a 0b 0c 0d # copy 0x0d0c0b0a to *EBX # ModR/M in binary: 00 (indirect mode) 000 (unused) 011 (dest EBX) +run: copy imm32 to r/m32 -+run: effective address is 0x60 (EBX) ++run: effective address is 0x00000060 (EBX) +run: imm32 is 0x0d0c0b0a :(before "End Single-Byte Opcodes") diff --git a/subx/016index_addressing.cc b/subx/016index_addressing.cc index 3501a522..0fe2aa71 100644 --- a/subx/016index_addressing.cc +++ b/subx/016index_addressing.cc @@ -11,8 +11,8 @@ == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x2000 (EAX) -+run: effective address is 0x2000 ++run: effective address is initially 0x00002000 (EAX) ++run: effective address is 0x00002000 +run: storing 0x00000011 :(before "End Mod 0 Special-cases(addr)") @@ -26,22 +26,22 @@ uint32_t effective_address_from_sib(uint8_t mod) { uint32_t addr = 0; if (base != EBP || mod != 0) { addr = Reg[base].u; - trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (" << rname(base) << ")" << end(); + trace(90, "run") << "effective address is initially 0x" << HEXWORD << addr << " (" << rname(base) << ")" << end(); } else { // base == EBP && mod == 0 addr = next32(); // ignore base - trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (disp32)" << end(); + trace(90, "run") << "effective address is initially 0x" << HEXWORD << addr << " (disp32)" << end(); } const uint8_t index = (sib>>3)&0x7; if (index == ESP) { // ignore index and scale - trace(90, "run") << "effective address is 0x" << std::hex << addr << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << addr << end(); } else { const uint8_t scale = (1 << (sib>>6)); addr += Reg[index].i*scale; // treat index register as signed. Maybe base as well? But we'll always ensure it's non-negative. - trace(90, "run") << "effective address is 0x" << std::hex << addr << " (after adding " << rname(index) << "*" << NUM(scale) << ")" << end(); + trace(90, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding " << rname(index) << "*" << NUM(scale) << ")" << end(); } return addr; } @@ -58,8 +58,8 @@ uint32_t effective_address_from_sib(uint8_t mod) { == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x1ffe (EAX) -+run: effective address is 0x2000 (after adding ECX*1) ++run: effective address is initially 0x00001ffe (EAX) ++run: effective address is 0x00002000 (after adding ECX*1) +run: storing 0x00000011 :(scenario add_r32_to_mem_at_displacement_using_sib) @@ -72,8 +72,8 @@ uint32_t effective_address_from_sib(uint8_t mod) { == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x2000 (disp32) -+run: effective address is 0x2000 ++run: effective address is initially 0x00002000 (disp32) ++run: effective address is 0x00002000 +run: storing 0x00000011 //: @@ -90,9 +90,9 @@ uint32_t effective_address_from_sib(uint8_t mod) { == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x1ff9 (EAX) -+run: effective address is 0x1ffe (after adding ECX*1) -+run: effective address is 0x2000 (after adding disp8) ++run: effective address is initially 0x00001ff9 (EAX) ++run: effective address is 0x00001ffe (after adding ECX*1) ++run: effective address is 0x00002000 (after adding disp8) +run: storing 0x00000011 :(before "End Mod 1 Special-cases(addr)") @@ -114,9 +114,9 @@ case 4: // exception: mod 0b01 rm 0b100 => incoming SIB (scale-index-base) byte == 0x2000 # data segment 01 00 00 00 # 1 +run: add EBX to r/m32 -+run: effective address is initially 0x1ff9 (EAX) -+run: effective address is 0x1ffe (after adding ECX*1) -+run: effective address is 0x2000 (after adding disp32) ++run: effective address is initially 0x00001ff9 (EAX) ++run: effective address is 0x00001ffe (after adding ECX*1) ++run: effective address is 0x00002000 (after adding disp32) +run: storing 0x00000011 :(before "End Mod 2 Special-cases(addr)") diff --git a/subx/019functions.cc b/subx/019functions.cc index a3b57ca5..bdeafad1 100644 --- a/subx/019functions.cc +++ b/subx/019functions.cc @@ -60,7 +60,7 @@ case 2: { // call function pointer at r/m32 == 0x2000 # data segment a0 00 00 00 # 0xa0 +run: call to r/m32 -+run: effective address is 0x2000 (EBX) ++run: effective address is 0x00002000 (EBX) +run: decrementing ESP to 0x00000060 +run: pushing value 0x00000003 +run: jumping to 0x000000a3 diff --git a/subx/021byte_addressing.cc b/subx/021byte_addressing.cc index 0a3b77d3..cffc4050 100644 --- a/subx/021byte_addressing.cc +++ b/subx/021byte_addressing.cc @@ -50,7 +50,7 @@ put_new(Name, "88", "copy r8 to r8/m8-at-r32"); == 0x2000 f0 cc bb aa # 0xf0 with more data in following bytes +run: copy BL to r8/m8-at-r32 -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0xab % CHECK_EQ(0xaabbccab, read_mem_u32(0x2000)); @@ -82,7 +82,7 @@ put_new(Name, "8a", "copy r8/m8-at-r32 to r8"); == 0x2000 # data segment ab ff ff ff # 0xab with more data in following bytes +run: copy r8/m8-at-r32 to BL -+run: effective address is 0x2000 (EAX) ++run: effective address is 0x00002000 (EAX) +run: storing 0xab # remaining bytes of EBX are *not* cleared +run: EBX now contains 0xaabbccab |