about summary refs log tree commit diff stats
path: root/subx/013immediate_addressing.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-10-15 01:59:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-10-15 01:59:11 -0700
commit95e5511ab8736f6fd9953fe66a05096b79afae16 (patch)
treea8602cedc6c70109c04d917fc111c845040d1e58 /subx/013immediate_addressing.cc
parent1ee02a2273a10cc30d5dd5e07be1e5ee6a392e55 (diff)
downloadmu-95e5511ab8736f6fd9953fe66a05096b79afae16.tar.gz
4069
subx: unconditional 'jump'
Diffstat (limited to 'subx/013immediate_addressing.cc')
-rw-r--r--subx/013immediate_addressing.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/subx/013immediate_addressing.cc b/subx/013immediate_addressing.cc
index dd1ce4c0..e97b9f6c 100644
--- a/subx/013immediate_addressing.cc
+++ b/subx/013immediate_addressing.cc
@@ -366,3 +366,49 @@ case 0xc7: {  // copy imm32 to r32
   *arg1 = arg2;
   break;
 }
+
+//:: jump
+
+:(scenario jump_rel8)
+# op  ModRM   SIB   displacement  immediate
+  eb                05                        # skip 1 instruction
+  05                              00 00 00 01
+  05                              00 00 00 02
++run: inst: 0x00000001
++run: jump 5
++run: inst: 0x00000008
+-run: inst: 0x00000003
+
+:(before "End Single-Byte Opcodes")
+case 0xeb: {  // jump rel8
+  int8_t offset = static_cast<int>(next());
+  trace(2, "run") << "jump " << NUM(offset) << end();
+  EIP += offset;
+  break;
+}
+
+//:
+
+:(scenario jump_rel16)
+# op  ModRM   SIB   displacement  immediate
+  e9                05 00                     # skip 1 instruction
+  05                              00 00 00 01
+  05                              00 00 00 02
++run: inst: 0x00000001
++run: jump 5
++run: inst: 0x00000009
+-run: inst: 0x00000003
+
+:(before "End Single-Byte Opcodes")
+case 0xe9: {  // jump rel8
+  int16_t offset = imm16();
+  trace(2, "run") << "jump " << offset << end();
+  EIP += offset;
+  break;
+}
+:(code)
+int16_t imm16() {
+  int16_t result = next();
+  result |= (next()<<8);
+  return result;
+}