diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-07 17:57:22 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-07 17:57:22 +0100 |
commit | 780b3a9daa6a4c4eca9c095ad990334b43cc0dfa (patch) | |
tree | b3da1957fbf5b0fedebf5e7732268bafeea86354 /qtmips_machine | |
parent | 60c7bfa8260f9aa68bd7947ecddfe64e030b0c7a (diff) | |
download | qtmips-780b3a9daa6a4c4eca9c095ad990334b43cc0dfa.tar.gz qtmips-780b3a9daa6a4c4eca9c095ad990334b43cc0dfa.tar.bz2 qtmips-780b3a9daa6a4c4eca9c095ad990334b43cc0dfa.zip |
Correct display of jump and branch instructions.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine')
-rw-r--r-- | qtmips_machine/instruction.cpp | 19 | ||||
-rw-r--r-- | qtmips_machine/instruction.h | 2 |
2 files changed, 15 insertions, 6 deletions
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; |