about summary refs log tree commit diff stats
path: root/014indirect_addressing.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-08 22:47:30 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-08 22:48:47 -0700
commit6b36e4dbc7749addeebe523992e0bcb62ad6b2d5 (patch)
treee041a9099e170c84c23a352d92fcf8efd536d788 /014indirect_addressing.cc
parentd9a05dfbb7ac73b31b1f3c1fb36a5324243da8a2 (diff)
downloadmu-6b36e4dbc7749addeebe523992e0bcb62ad6b2d5.tar.gz
6760
Fix a couple of subtle bugs.

- the VM was conditionally reading from the instruction stream, so that
  other bugs got masked by decoding errors.
- push-n-bytes was clobbering eax.
Diffstat (limited to '014indirect_addressing.cc')
-rw-r--r--014indirect_addressing.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/014indirect_addressing.cc b/014indirect_addressing.cc
index 19d4d509..fa679d6f 100644
--- a/014indirect_addressing.cc
+++ b/014indirect_addressing.cc
@@ -936,7 +936,7 @@ void test_add_r32_to_mem_at_r32_plus_disp32() {
 }
 
 :(before "End Mod Special-cases(addr)")
-case 2:  // indirect + disp32 addressing
+case 2: {  // indirect + disp32 addressing
   switch (rm) {
   default:
     addr = Reg[rm].u;
@@ -944,11 +944,16 @@ case 2:  // indirect + disp32 addressing
     break;
   // End Mod 2 Special-cases(addr)
   }
+  int32_t displacement = static_cast<int32_t>(next32());
   if (addr > 0) {
-    addr += next32();
+    addr += displacement;
     trace(Callstack_depth+1, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding disp32)" << end();
   }
+  else {
+    trace(Callstack_depth+1, "run") << "null address; skipping displacement" << end();
+  }
   break;
+}
 
 :(code)
 void test_add_r32_to_mem_at_r32_plus_negative_disp32() {