From f39429b60dbceaa5ef4c2cf8a30d20fb58e3bb2e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 11 Aug 2018 10:51:31 -0700 Subject: 4504 --- subx/030---operands.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/subx/030---operands.cc b/subx/030---operands.cc index 9326e9d8..68a37324 100644 --- a/subx/030---operands.cc +++ b/subx/030---operands.cc @@ -245,8 +245,10 @@ void add_imm_bytes(const line& in, line& out) { void emit_hex_bytes(line& out, const word& w, int num) { assert(num <= 4); - if (!is_hex_int(w.data)) { + if (num == 1 || !is_hex_int(w.data)) { out.words.push_back(w); + if (is_hex_int(w.data)) + out.words.back().data = hex_byte_to_string(parse_int(w.data)); return; } emit_hex_bytes(out, static_cast(parse_int(w.data)), num); @@ -261,14 +263,18 @@ void emit_hex_bytes(line& out, uint32_t val, int num) { } word hex_byte_text(uint8_t val) { - ostringstream out; - out << HEXBYTE << NUM(val); word result; - result.data = out.str(); - result.original = out.str()+"/auto"; + result.data = hex_byte_to_string(val); + result.original = result.data+"/auto"; return result; } +string hex_byte_to_string(uint8_t val) { + ostringstream out; + out << HEXBYTE << NUM(val); + return out.str(); +} + string to_string(const vector& in) { ostringstream out; for (int i = 0; i < SIZE(in); ++i) { @@ -278,6 +284,17 @@ string to_string(const vector& in) { return out.str(); } +:(before "End Unit Tests") +void test_preserve_metadata_when_emitting_single_byte() { + word in; + in.data = "f0"; + in.original = "f0/foo"; + line out; + emit_hex_bytes(out, in, 1); + CHECK_EQ(out.words.at(0).data, "f0"); + CHECK_EQ(out.words.at(0).original, "f0/foo"); +} + :(scenario pack_disp8) == 0x1 74 2/disp8 # jump 2 bytes away if ZF is set -- cgit 1.4.1-2-gfad0