diff options
-rw-r--r-- | qtmips_gui/coreview/instructionview.cpp | 2 | ||||
-rw-r--r-- | qtmips_gui/programdock.cpp | 2 | ||||
-rw-r--r-- | qtmips_machine/instruction.cpp | 19 | ||||
-rw-r--r-- | qtmips_machine/instruction.h | 2 |
4 files changed, 17 insertions, 8 deletions
diff --git a/qtmips_gui/coreview/instructionview.cpp b/qtmips_gui/coreview/instructionview.cpp index 342a1d4..d989b7b 100644 --- a/qtmips_gui/coreview/instructionview.cpp +++ b/qtmips_gui/coreview/instructionview.cpp @@ -67,7 +67,7 @@ void InstructionView::paint(QPainter *painter, const QStyleOptionGraphicsItem *o void InstructionView::instruction_update(const machine::Instruction &i, std::uint32_t inst_addr) { QRectF prev_box = boundingRect(); - text.setText(i.to_str()); + text.setText(i.to_str(inst_addr)); QRectF box = text.boundingRect(); text.setPos(-box.width()/2, GAP); update(prev_box.united(boundingRect())); diff --git a/qtmips_gui/programdock.cpp b/qtmips_gui/programdock.cpp index 192352b..4c379eb 100644 --- a/qtmips_gui/programdock.cpp +++ b/qtmips_gui/programdock.cpp @@ -111,7 +111,7 @@ QList<QWidget*> ProgramView::row_widget(std::uint32_t address, QWidget *parent) l->setFont(f); l->setMinimumWidth(60); if (memory != nullptr) - l->setText(machine::Instruction(memory->read_word(address)).to_str()); + l->setText(machine::Instruction(memory->read_word(address)).to_str(address)); widgs.append(l); return widgs; 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; |