From 780b3a9daa6a4c4eca9c095ad990334b43cc0dfa Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 7 Feb 2019 17:57:22 +0100 Subject: Correct display of jump and branch instructions. Signed-off-by: Pavel Pisa --- qtmips_machine/instruction.cpp | 19 ++++++++++++++----- qtmips_machine/instruction.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'qtmips_machine') diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp index db58d2a..393760c 100644 --- a/qtmips_machine/instruction.cpp +++ b/qtmips_machine/instruction.cpp @@ -530,7 +530,7 @@ Instruction &Instruction::operator=(const Instruction &c) { return *this; } -QString Instruction::to_str() const { +QString Instruction::to_str(std::int32_t inst_addr) const { const InstructionMap &im = InstructionMapFind(dt); // TODO there are exception where some fields are zero and such so we should not print them in such case if (dt == 0) @@ -542,7 +542,7 @@ QString Instruction::to_str() const { res += im.name; if (im.flags & IMF_MEM) { res += " $" + QString::number(rt()); - res += ", 0x" + QString::number(immediate(), 16).toUpper() + "(" + QString::number(rs()) + ")"; + res += ", 0x" + QString::number(immediate(), 16).toUpper() + "($" + QString::number(rs()) + ")"; } else { if (im.flags & IMF_REGWRITE) { res += next_delim + "$" + QString::number(rt()); @@ -556,13 +556,22 @@ QString Instruction::to_str() const { res += next_delim + "$" + QString::number(rt()); next_delim = ", "; } - res += next_delim + "0x" + QString::number(immediate(), 16).toUpper(); + if (im.flags & IMF_BRANCH) { + std::uint32_t target = inst_addr + ((int16_t)immediate() << 2) + 4; + res += next_delim + "0x" + QString::number(target, 16).toUpper(); + } else if (im.flags & IMF_ZERO_EXTEND) { + res += next_delim + "0x" + QString::number(immediate(), 16).toUpper(); + } else { + res += next_delim + QString::number((std::int16_t)immediate(), 10).toUpper(); + } } break; case T_J: res += im.name; - // TODO we need to know instruction address to expand address section by it - res += " 0x" + QString::number(address(), 16).toUpper(); + { + std::uint32_t target = (inst_addr & 0xF0000000) | (address() << 2); + res += " 0x" + QString::number(target, 16).toUpper(); + } break; case T_R: { diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h index b26d9ac..e896ace 100644 --- a/qtmips_machine/instruction.h +++ b/qtmips_machine/instruction.h @@ -110,7 +110,7 @@ public: bool operator!=(const Instruction &c) const; Instruction &operator=(const Instruction &c); - QString to_str() const; + QString to_str(std::int32_t inst_addr = 0) const; private: std::uint32_t dt; -- cgit v1.2.3