about summary refs log tree commit diff stats
path: root/subx/034compute_segment_address.cc
diff options
context:
space:
mode:
Diffstat (limited to 'subx/034compute_segment_address.cc')
-rw-r--r--subx/034compute_segment_address.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/subx/034compute_segment_address.cc b/subx/034compute_segment_address.cc
index f6513114..b302e4d8 100644
--- a/subx/034compute_segment_address.cc
+++ b/subx/034compute_segment_address.cc
@@ -111,17 +111,19 @@ uint32_t size_of(const segment& s) {
 // Assumes all bitfields are packed.
 uint32_t num_bytes(const line& inst) {
   uint32_t sum = 0;
-  for (int i = 0;  i < SIZE(inst.words);  ++i) {
-    const word& curr = inst.words.at(i);
-    if (has_operand_metadata(curr, "disp32") || has_operand_metadata(curr, "imm32"))  // only multi-byte operands
-      sum += 4;
-    // End num_bytes(curr) Special-cases
-    else
-      sum++;
-  }
+  for (int i = 0;  i < SIZE(inst.words);  ++i)
+    sum += size_of(inst.words.at(i));
   return sum;
 }
 
+int size_of(const word& w) {
+  if (has_operand_metadata(w, "disp32") || has_operand_metadata(w, "imm32"))
+    return 4;
+  // End size_of(word w) Special-cases
+  else
+    return 1;
+}
+
 //: Dependencies:
 //: - We'd like to compute segment addresses before setting up global variables,
 //:   because computing addresses for global variables requires knowing where