about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-26 22:32:57 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-26 22:32:57 -0700
commit365f762f8ffe2596b538aa9da711b36806126899 (patch)
tree2059f4499e4abbbad6b9309a5c9b9ba037b84979
parentb7655c98122d8ca99815dc1a0725756d3e678c95 (diff)
downloadmu-365f762f8ffe2596b538aa9da711b36806126899.tar.gz
4431 - operate exclusively in hex
Was confusing having numbers without an explicit base sometimes be hex
and sometimes not, based on their metadata.

By convention I don't bother with the '0x' for instructions, or for
single-digit numbers that are equal to their decimal representation. But
I could and it would still work.
-rw-r--r--subx/023check_operand_sizes.cc4
-rw-r--r--subx/024pack_instructions.cc4
-rw-r--r--subx/025non_code_segment.cc2
-rw-r--r--subx/ex1.2.subx4
-rw-r--r--subx/ex2.subx2
-rw-r--r--subx/ex3.subx6
-rw-r--r--subx/ex4.subx6
7 files changed, 13 insertions, 15 deletions
diff --git a/subx/023check_operand_sizes.cc b/subx/023check_operand_sizes.cc
index 8ad3b1aa..be4327f1 100644
--- a/subx/023check_operand_sizes.cc
+++ b/subx/023check_operand_sizes.cc
@@ -56,9 +56,7 @@ void check_operand_bounds(const word& w) {
 int32_t parse_int(const string& s) {
   istringstream in(s);
   int32_t result = 0;
-  if (starts_with(s, "0x"))
-    in >> std::hex;
-  in >> result;
+  in >> std::hex >> result;
   if (!in) {
     raise << "not a number: " << s << '\n' << end();
     return 0;
diff --git a/subx/024pack_instructions.cc b/subx/024pack_instructions.cc
index 0ff5050d..44d06eb7 100644
--- a/subx/024pack_instructions.cc
+++ b/subx/024pack_instructions.cc
@@ -6,8 +6,8 @@
 # instruction                     effective address                                           operand     displacement    immediate
 # op          subop               mod             rm32          base      index     scale     r32
 # 1-3 bytes   3 bits              2 bits          3 bits        3 bits    3 bits    2 bits    2 bits      0/1/2/4 bytes   0/1/2/4 bytes
-  bb                                                                                                                      42/imm32          # copy 42 to EBX
-+translate: packing instruction 'bb 42/imm32'
+  bb                                                                                                                      0x2a/imm32        # copy 42 to EBX
++translate: packing instruction 'bb 0x2a/imm32'
 +translate: instruction after packing: 'bb 2a 00 00 00'
 +run: copy imm32 0x0000002a to EBX
 
diff --git a/subx/025non_code_segment.cc b/subx/025non_code_segment.cc
index bf21d253..ba713cca 100644
--- a/subx/025non_code_segment.cc
+++ b/subx/025non_code_segment.cc
@@ -3,7 +3,7 @@
 :(scenario operand_metadata_outside_code_segment)
 % Hide_errors = true;
 == 0x1  # code segment
-cd 128/imm8
+cd 0x80/imm8
 == 0x1000  # data segment
 cd 12/imm8
 +error: 12/imm8: metadata imm8 is only allowed in the (first) code segment
diff --git a/subx/ex1.2.subx b/subx/ex1.2.subx
index 1dac17e5..a3eee2d9 100644
--- a/subx/ex1.2.subx
+++ b/subx/ex1.2.subx
@@ -9,9 +9,9 @@
 # instruction                     effective address                                           operand     displacement    immediate
 # op          subop               mod             rm32          base      index     scale     r32
 # 1-3 bytes   3 bits              2 bits          3 bits        3 bits    3 bits    2 bits    2 bits      0/1/2/4 bytes   0/1/2/4 bytes
-  bb                                                                                                                      42/imm32          # copy 0x2a (42) to EBX
+  bb                                                                                                                      2a/imm32          # copy 42 to EBX
   # exit(EBX)
   b8                                                                                                                      1/imm32           # copy 1 to EAX
-  cd                                                                                                                      128/imm8          # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 # vim:ft=subx
diff --git a/subx/ex2.subx b/subx/ex2.subx
index 19c9bb93..82d84104 100644
--- a/subx/ex2.subx
+++ b/subx/ex2.subx
@@ -15,6 +15,6 @@
   81          0/add/subop         3/mod/direct    3/ebx/rm32                                                              1/imm32           # add 1 to EBX
   # exit(EBX)
   b8                                                                                                                      1/imm32           # copy 1 to EAX
-  cd                                                                                                                      128/imm8          # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 # vim:ft=subx
diff --git a/subx/ex3.subx b/subx/ex3.subx
index f9df8703..4dcb10e9 100644
--- a/subx/ex3.subx
+++ b/subx/ex3.subx
@@ -19,14 +19,14 @@
 
 # 10: loop: 0x0804805e
   # while (ECX <= 10)
-  81            7/subop/compare   3/mod/direct    1/rm32/ecx                                                              10/imm32          # compare ECX, 10/imm
-  7f                                                                                                      10/disp8                          # jump-if-greater exit
+  81            7/subop/compare   3/mod/direct    1/rm32/ecx                                                              0xa/imm32         # compare ECX, 10/imm
+  7f                                                                                                      0xa/disp8                         # jump-if-greater exit (+10 bytes)
   # EBX += ECX
   01                              3/mod/direct    3/rm32/ebx                                  1/r32/ecx                                     # add ECX to EBX
   # ECX++
   81            0/subop/add       3/mod/direct    1/rm32/ecx                                                              1/imm32           # add 1 to ECX
   # loop
-  eb                                                                                                      -18/disp8                         # jump loop
+  eb                                                                                                      -0x12/disp8                       # jump loop (-18 bytes)
 
 # 28: exit: 0x08048070
   # exit(EBX)
diff --git a/subx/ex4.subx b/subx/ex4.subx
index 81c65dae..b8d5ca10 100644
--- a/subx/ex4.subx
+++ b/subx/ex4.subx
@@ -19,7 +19,7 @@
   # syscall = read
   b8                                                                                                                      3/imm32           # copy 3 to EAX
   # call
-  cd                                                                                                                      128/imm8          # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
   ## write(stdout, x, 1)
   # fd = 1 (stdout)
@@ -31,11 +31,11 @@
   # syscall = write
   b8                                                                                                                      4/imm32           # copy 4 to EAX
   # call
-  cd                                                                                                                      128/imm8          # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
   ## exit(EBX)
   b8                                                                                                                      1/imm32           # copy 1 to EAX
-  cd                                                                                                                      128/imm8          # int 80h
+  cd                                                                                                                      0x80/imm8         # int 80h
 
 == 0x080490a7
 00 00 00 00  # space for read() to write to