about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-09 18:02:44 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-09 18:05:27 -0700
commit58d03e437a95da78f612f833a249376aa202b502 (patch)
tree3990fb60957546376462122bff8dc0ee4fa24c5b
parent4a96b659ff1dc16b78ba5fc607d49276b6d76c2a (diff)
downloadmu-58d03e437a95da78f612f833a249376aa202b502.tar.gz
bug: null address messing up instruction decode
Leads to a bad error message.
-rw-r--r--subx/014indirect_addressing.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/subx/014indirect_addressing.cc b/subx/014indirect_addressing.cc
index dd00c614..3767c46d 100644
--- a/subx/014indirect_addressing.cc
+++ b/subx/014indirect_addressing.cc
@@ -874,7 +874,7 @@ void test_add_r32_to_mem_at_r32_plus_disp8() {
 }
 
 :(before "End Mod Special-cases(addr)")
-case 1:  // indirect + disp8 addressing
+case 1: {  // indirect + disp8 addressing
   switch (rm) {
   default:
     addr = Reg[rm].u;
@@ -882,11 +882,16 @@ case 1:  // indirect + disp8 addressing
     break;
   // End Mod 1 Special-cases(addr)
   }
+  int8_t displacement = static_cast<int8_t>(next());
   if (addr > 0) {
-    addr += static_cast<int8_t>(next());
+    addr += displacement;
     trace(Callstack_depth+1, "run") << "effective address is 0x" << HEXWORD << addr << " (after adding disp8)" << end();
   }
+  else {
+    trace(Callstack_depth+1, "run") << "null address; skipping displacement" << end();
+  }
   break;
+}
 
 :(code)
 void test_add_r32_to_mem_at_r32_plus_negative_disp8() {