about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-10-14 19:18:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-10-14 19:18:51 -0700
commit0cb3c774b207c8a94bf9f9775e99e7d593d1e4fe (patch)
tree8f0cc39f13b55f310e974f69887c078f7b27f074 /subx
parentf603d9f2d38a836f452b692c331728ef72a05721 (diff)
downloadmu-0cb3c774b207c8a94bf9f9775e99e7d593d1e4fe.tar.gz
4064
Diffstat (limited to 'subx')
-rw-r--r--subx/010core.cc4
-rw-r--r--subx/012indirect_addressing.cc41
-rw-r--r--subx/013immediate_addressing.cc16
3 files changed, 20 insertions, 41 deletions
diff --git a/subx/010core.cc b/subx/010core.cc
index 9229143b..0713ec1d 100644
--- a/subx/010core.cc
+++ b/subx/010core.cc
@@ -68,6 +68,10 @@ uint32_t End_of_program = 0;
 Mem.clear();
 Mem.resize(1024);
 End_of_program = 0;
+:(before "End Includes")
+// depends on Mem being laid out contiguously (so you can't use a map, etc.)
+// and on the host also being little-endian
+#define SET_WORD_IN_MEM(addr, val)  *reinterpret_cast<int32_t*>(&Mem.at(addr)) = val;
 
 //:: core interpreter loop
 
diff --git a/subx/012indirect_addressing.cc b/subx/012indirect_addressing.cc
index 4095fb1b..e209d690 100644
--- a/subx/012indirect_addressing.cc
+++ b/subx/012indirect_addressing.cc
@@ -3,8 +3,7 @@
 :(scenario add_r32_to_mem_at_r32)
 % Reg[3].i = 0x10;
 % Reg[0].i = 0x60;
-# word in addresses 0x60-0x63 has value 1
-% Mem.at(0x60) = 1;
+% SET_WORD_IN_MEM(0x60, 1);
 # op  ModR/M  SIB   displacement  immediate
   01  18                                     # add EBX (reg 3) to *EAX (reg 0)
 +run: add reg 3 to effective address
@@ -29,7 +28,7 @@ case 0:
 :(scenario add_mem_at_r32_to_r32)
 % Reg[0].i = 0x60;
 % Reg[3].i = 0x10;
-% Mem.at(0x60) = 1;
+% SET_WORD_IN_MEM(0x60, 1);
 # op  ModR/M  SIB   displacement  immediate
   03  18                                      # add *EAX (reg 0) to EBX (reg 3)
 +run: add effective address to reg 3
@@ -50,7 +49,7 @@ case 0x03: {  // add r/m32 to r32
 
 :(scenario subtract_r32_from_mem_at_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 10;
+% SET_WORD_IN_MEM(0x60, 10);
 % Reg[3].i = 1;
 # op  ModRM   SIB   displacement  immediate
   29  18                                      # subtract EBX (reg 3) from *EAX (reg 0)
@@ -62,7 +61,7 @@ case 0x03: {  // add r/m32 to r32
 
 :(scenario subtract_mem_at_r32_from_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 1;
+% SET_WORD_IN_MEM(0x60, 1);
 % Reg[3].i = 10;
 # op  ModRM   SIB   displacement  immediate
   2b  18                                      # subtract *EAX (reg 0) from EBX (reg 3)
@@ -84,10 +83,7 @@ case 0x2b: {  // subtract r/m32 from r32
 
 :(scenario and_r32_with_mem_at_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0x0d;
-% Mem.at(0x61) = 0x0c;
-% Mem.at(0x62) = 0x0b;
-% Mem.at(0x63) = 0x0a;
+% SET_WORD_IN_MEM(0x60, 0x0a0b0c0d);
 % Reg[3].i = 0xff;
 # op  ModRM   SIB   displacement  immediate
   21  18                                      # and EBX (reg 3) with *EAX (reg 0)
@@ -99,7 +95,7 @@ case 0x2b: {  // subtract r/m32 from r32
 
 :(scenario and_mem_at_r32_with_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0xff;
+% SET_WORD_IN_MEM(0x60, 0x000000ff);
 % Reg[3].i = 0x0a0b0c0d;
 # op  ModRM   SIB   displacement  immediate
   23  18                                      # and *EAX (reg 0) with EBX (reg 3)
@@ -121,10 +117,7 @@ case 0x23: {  // and r/m32 with r32
 
 :(scenario or_r32_with_mem_at_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0x0d;
-% Mem.at(0x61) = 0x0c;
-% Mem.at(0x62) = 0x0b;
-% Mem.at(0x63) = 0x0a;
+% SET_WORD_IN_MEM(0x60, 0x0a0b0c0d);
 % Reg[3].i = 0xa0b0c0d0;
 # op  ModRM   SIB   displacement  immediate
   09  18                                      # or EBX (reg 3) with *EAX (reg 0)
@@ -136,10 +129,7 @@ case 0x23: {  // and r/m32 with r32
 
 :(scenario or_mem_at_r32_with_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0x0d;
-% Mem.at(0x61) = 0x0c;
-% Mem.at(0x62) = 0x0b;
-% Mem.at(0x63) = 0x0a;
+% SET_WORD_IN_MEM(0x60, 0x0a0b0c0d);
 % Reg[3].i = 0xa0b0c0d0;
 # op  ModRM   SIB   displacement  immediate
   0b  18                                      # or *EAX (reg 0) with EBX (reg 3)
@@ -161,10 +151,7 @@ case 0x0b: {  // or r/m32 with r32
 
 :(scenario xor_r32_with_mem_at_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0x0d;
-% Mem.at(0x61) = 0x0c;
-% Mem.at(0x62) = 0xbb;
-% Mem.at(0x63) = 0xaa;
+% SET_WORD_IN_MEM(0x60, 0xaabb0c0d);
 % Reg[3].i = 0xa0b0c0d0;
 # op  ModRM   SIB   displacement  immediate
   31  18                                      # xor EBX (reg 3) with *EAX (reg 0)
@@ -176,10 +163,7 @@ case 0x0b: {  // or r/m32 with r32
 
 :(scenario xor_mem_at_r32_with_r32)
 % Reg[0].i = 0x60;
-% Mem.at(0x60) = 0x0d;
-% Mem.at(0x61) = 0x0c;
-% Mem.at(0x62) = 0x0b;
-% Mem.at(0x63) = 0x0a;
+% SET_WORD_IN_MEM(0x60, 0x0a0b0c0d);
 % Reg[3].i = 0xa0b0c0d0;
 # op  ModRM   SIB   displacement  immediate
   33  18                                      # xor *EAX (reg 0) with EBX (reg 3)
@@ -202,10 +186,7 @@ case 0x33: {  // xor r/m32 with r32
 :(scenario not_r32_with_mem_at_r32)
 % Reg[3].i = 0x60;
 # word at 0x60 is 0x0f0f00ff
-% Mem.at(0x60) = 0xff;
-% Mem.at(0x61) = 0x00;
-% Mem.at(0x62) = 0x0f;
-% Mem.at(0x63) = 0x0f;
+% SET_WORD_IN_MEM(0x60, 0x0f0f00ff);
 # op  ModRM   SIB   displacement  immediate
   f7  03                                      # negate *EBX (reg 3)
 +run: 'not' of effective address
diff --git a/subx/013immediate_addressing.cc b/subx/013immediate_addressing.cc
index 143438cd..ff08dea5 100644
--- a/subx/013immediate_addressing.cc
+++ b/subx/013immediate_addressing.cc
@@ -33,7 +33,7 @@ case 0x81: {  // combine imm32 with r/m32
 
 :(scenario add_imm32_to_mem_at_r32)
 % Reg[3].i = 0x60;
-% Mem.at(0x60) = 1;
+% SET_WORD_IN_MEM(0x60, 1);
 # op  ModR/M  SIB   displacement  immediate
   81  03                          0a 0b 0c 0d  # add 0x0d0c0b0a to *EBX (reg 3)
 +run: combine imm32 0x0d0c0b0a with effective address
@@ -62,7 +62,7 @@ case 0x2d: {  // subtract imm32 from EAX
 
 :(scenario subtract_imm32_from_mem_at_r32)
 % Reg[3].i = 0x60;
-% Mem.at(0x60) = 10;
+% SET_WORD_IN_MEM(0x60, 10);
 # op  ModRM   SIB   displacement  immediate
   81  2b                          01 00 00 00  # subtract 1 from *EBX (reg 3)
 +run: combine imm32 0x00000001 with effective address
@@ -109,7 +109,7 @@ case 0x25: {  // and imm32 with EAX
 
 :(scenario and_imm32_with_mem_at_r32)
 % Reg[3].i = 0x60;
-% Mem.at(0x60) = 0xff;
+% SET_WORD_IN_MEM(0x60, 0x000000ff);
 # op  ModRM   SIB   displacement  immediate
   81  23                          0a 0b 0c 0d  # and 0x0d0c0b0a with *EBX (reg 3)
 +run: combine imm32 0x0d0c0b0a with effective address
@@ -156,10 +156,7 @@ case 0x0d: {  // or imm32 with EAX
 
 :(scenario or_imm32_with_mem_at_r32)
 % Reg[3].i = 0x60;
-% Mem.at(0x60) = 0xa0;
-% Mem.at(0x61) = 0xb0;
-% Mem.at(0x62) = 0xc0;
-% Mem.at(0x63) = 0xd0;
+% SET_WORD_IN_MEM(0x60, 0xd0c0b0a0);
 # op  ModRM   SIB   displacement  immediate
   81  0b                          0a 0b 0c 0d  # or 0x0d0c0b0a with *EBX (reg 3)
 +run: combine imm32 0x0d0c0b0a with effective address
@@ -206,10 +203,7 @@ case 0x35: {  // xor imm32 with EAX
 
 :(scenario xor_imm32_with_mem_at_r32)
 % Reg[3].i = 0x60;
-% Mem.at(0x60) = 0xa0;
-% Mem.at(0x61) = 0xb0;
-% Mem.at(0x62) = 0xc0;
-% Mem.at(0x63) = 0xd0;
+% SET_WORD_IN_MEM(0x60, 0xd0c0b0a0);
 # op  ModRM   SIB   displacement  immediate
   81  33                          0a 0b 0c 0d  # xor 0x0d0c0b0a with *EBX (reg 3)
 +run: combine imm32 0x0d0c0b0a with effective address