about summary refs log tree commit diff stats
path: root/subx/012indirect_addressing.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-10-18 02:27:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-10-18 02:27:56 -0700
commit8a0268317fbce2baa2e5119c796750ea6c80a813 (patch)
tree786bc1d7f5c6db61288d6b3e4ed6a145c219d32f /subx/012indirect_addressing.cc
parent099ed980c4e137fe37a5150668561175aab87c0d (diff)
downloadmu-8a0268317fbce2baa2e5119c796750ea6c80a813.tar.gz
4084
subx: extract helpers for 'push' and 'pop'. We will be using them in
'call' and 'ret' as well.
Diffstat (limited to 'subx/012indirect_addressing.cc')
-rw-r--r--subx/012indirect_addressing.cc19
1 files changed, 6 insertions, 13 deletions
diff --git a/subx/012indirect_addressing.cc b/subx/012indirect_addressing.cc
index 37d82a3f..f4e8c665 100644
--- a/subx/012indirect_addressing.cc
+++ b/subx/012indirect_addressing.cc
@@ -349,18 +349,14 @@ case 0xff: {  // jump to r/m32
   ff  30                                      # push *EAX (reg 0) to stack
 +run: push effective address
 +run: effective address is mem at address 0x60 (reg 0)
-+run: ESP is now 0x00000010
-+run: contents at ESP: 0x000000af
++run: decrementing ESP to 0x00000010
++run: pushing value 0x000000af
 
 :(before "End Op ff Subops")
 case 6: {
   trace(2, "run") << "push effective address" << end();
   const int32_t* val = effective_address(modrm);
-  trace(2, "run") << "pushing value 0x" << HEXWORD << *val << end();
-  Reg[ESP].u -= 4;
-  *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u)) = *val;
-  trace(2, "run") << "ESP is now 0x" << HEXWORD << Reg[ESP].u << end();
-  trace(2, "run") << "contents at ESP: 0x" << HEXWORD << *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u)) << end();
+  push(*val);
   break;
 }
 
@@ -374,8 +370,8 @@ case 6: {
   8f  00                                      # pop stack into *EAX (reg 0)
 +run: pop into effective address
 +run: effective address is mem at address 0x60 (reg 0)
-+run: storing 0x00000030
-+run: ESP is now 0x00000014
++run: popping value 0x00000030
++run: incrementing ESP to 0x00000014
 
 :(before "End Single-Byte Opcodes")
 case 0x8f: {  // pop stack into r/m32
@@ -385,10 +381,7 @@ case 0x8f: {  // pop stack into r/m32
     case 0: {
       trace(2, "run") << "pop into effective address" << end();
       int32_t* dest = effective_address(modrm);
-      *dest = *reinterpret_cast<uint32_t*>(&Mem.at(Reg[ESP].u));
-      trace(2, "run") << "storing 0x" << HEXWORD << *dest << end();
-      Reg[ESP].u += 4;
-      trace(2, "run") << "ESP is now 0x" << HEXWORD << Reg[ESP].u << end();
+      *dest = pop();
       break;
     }
   }