about summary refs log tree commit diff stats
path: root/subx/011direct_addressing.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-10-14 22:53:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-10-14 23:00:05 -0700
commitc67ca4b92674620f3cae3b9301471e0321a7936c (patch)
treefb471c4ae56d38f6731d913b1450eec025ae7351 /subx/011direct_addressing.cc
parent0cb3c774b207c8a94bf9f9775e99e7d593d1e4fe (diff)
downloadmu-c67ca4b92674620f3cae3b9301471e0321a7936c.tar.gz
4065
subx: 'compare'

Hopefully I've implemented the 'sense' of comparisons right..
Diffstat (limited to 'subx/011direct_addressing.cc')
-rw-r--r--subx/011direct_addressing.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/subx/011direct_addressing.cc b/subx/011direct_addressing.cc
index a1d83b8c..facc8378 100644
--- a/subx/011direct_addressing.cc
+++ b/subx/011direct_addressing.cc
@@ -148,3 +148,48 @@ case 0xf7: {  // xor r32 with r/m32
   OF = false;
   break;
 }
+
+//:: compare
+
+:(scenario compare_r32_with_r32_greater)
+% Reg[0].i = 0x0a0b0c0d;
+% Reg[3].i = 0x0a0b0c07;
+# op  ModRM   SIB   displacement  immediate
+  39  d8                                      # compare EBX (reg 3) with EAX (reg 0)
++run: compare reg 3 with effective address
++run: effective address is reg 0
++run: SF=0; ZF=0; OF=0
+
+:(before "End Single-Byte Opcodes")
+case 0x39: {  // compare r32 with r/m32
+  uint8_t modrm = next();
+  uint8_t reg2 = (modrm>>3)&0x7;
+  trace(2, "run") << "compare reg " << NUM(reg2) << " with effective address" << end();
+  int32_t* arg1 = effective_address(modrm);
+  int32_t arg2 = Reg[reg2].i;
+  int32_t tmp1 = *arg1 - arg2;
+  SF = (tmp1 < 0);
+  ZF = (tmp1 == 0);
+  int64_t tmp2 = *arg1 - arg2;
+  OF = (tmp1 != tmp2);
+  trace(2, "run") << "SF=" << SF << "; ZF=" << ZF << "; OF=" << OF << end();
+  break;
+}
+
+:(scenario compare_r32_with_r32_lesser)
+% Reg[0].i = 0x0a0b0c07;
+% Reg[3].i = 0x0a0b0c0d;
+# op  ModRM   SIB   displacement  immediate
+  39  d8                                      # compare EBX (reg 3) with EAX (reg 0)
++run: compare reg 3 with effective address
++run: effective address is reg 0
++run: SF=1; ZF=0; OF=0
+
+:(scenario compare_r32_with_r32_equal)
+% Reg[0].i = 0x0a0b0c0d;
+% Reg[3].i = 0x0a0b0c0d;
+# op  ModRM   SIB   displacement  immediate
+  39  d8                                      # compare EBX (reg 3) with EAX (reg 0)
++run: compare reg 3 with effective address
++run: effective address is reg 0
++run: SF=0; ZF=1; OF=0