about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-11-24 20:53:32 -0800
committerKartik Agaram <vc@akkartik.com>2018-11-24 20:53:50 -0800
commit3c46d5a221542195aca58f8f7061f59cda479927 (patch)
tree95847d3f9449ca1c0f4e6329c309866155d4a17a
parentba196240ff575d6226751f4373ae60eff3fba0bf (diff)
downloadmu-3c46d5a221542195aca58f8f7061f59cda479927.tar.gz
4771
I stopped handling disp16 at some point, and using instructions with such
an operand messes up segment alignment when generating ELF binaries.

I don't test my ELF generation. This is a sign that maybe I should start.
-rw-r--r--subx/034compute_segment_address.cc2
-rw-r--r--subx/035labels.cc5
2 files changed, 7 insertions, 0 deletions
diff --git a/subx/034compute_segment_address.cc b/subx/034compute_segment_address.cc
index cf5b789d..b6c191e4 100644
--- a/subx/034compute_segment_address.cc
+++ b/subx/034compute_segment_address.cc
@@ -119,6 +119,8 @@ uint32_t num_bytes(const line& inst) {
 int size_of(const word& w) {
   if (has_operand_metadata(w, "disp32") || has_operand_metadata(w, "imm32"))
     return 4;
+  else if (has_operand_metadata(w, "disp16"))
+    return 2;
   // End size_of(word w) Special-cases
   else
     return 1;
diff --git a/subx/035labels.cc b/subx/035labels.cc
index e07cede8..cbe83802 100644
--- a/subx/035labels.cc
+++ b/subx/035labels.cc
@@ -105,6 +105,11 @@ void compute_byte_indices_for_labels(const segment& code, map<string, int32_t>&
           raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end();
         current_byte += 4;
       }
+      else if (has_operand_metadata(curr, "imm16")) {
+        if (*curr.data.rbegin() == ':')
+          raise << "'" << to_string(inst) << "': don't use ':' when jumping to labels\n" << end();
+        current_byte += 2;
+      }
       // automatically handle /disp8 and /imm8 here
       else if (*curr.data.rbegin() != ':') {
         ++current_byte;