From 8f6d939e8d0fdec39c53da65cfb89f288d99eb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 25 Nov 2017 16:14:19 +0100 Subject: Implement instructions for moving from and to HI and LO registers --- qtmips_machine/alu.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'qtmips_machine/alu.cpp') diff --git a/qtmips_machine/alu.cpp b/qtmips_machine/alu.cpp index 554874a..07e174e 100644 --- a/qtmips_machine/alu.cpp +++ b/qtmips_machine/alu.cpp @@ -1,7 +1,7 @@ #include "alu.h" #include "qtmipsexception.h" -std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa) { +std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa, Registers *regs) { switch(operation) { case ALU_OP_SLL: return t << sa; @@ -17,6 +17,16 @@ std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t case ALU_OP_SRAV: // TODO is this correct implementation? (Should we be masking top most bit?) return ((t & 0x7fffffff) >> s) | (t & 0x80000000); + case ALU_OP_MFHI: + return regs->read_hi_lo(true); + case ALU_OP_MTHI: + regs->write_hi_lo(true, s); + return 0x0; + case ALU_OP_MFLO: + return regs->read_hi_lo(false); + case ALU_OP_MTLO: + regs->write_hi_lo(false, s); + return 0x0; case ALU_OP_ADD: if (s > (0xFFFFFFFF - t)) throw QTMIPS_EXCEPTION(Overflow, "ADD operation overflow/underflow", QString::number(s) + QString(" + ") + QString::number(t)); -- cgit v1.2.3