aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/alu.cpp
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-11-25 16:14:19 +0100
committerKarel Kočí <cynerd@email.cz>2017-11-25 16:14:19 +0100
commit8f6d939e8d0fdec39c53da65cfb89f288d99eb82 (patch)
treecadb68d5720dd7d682e9492f72fea7239248862c /qtmips_machine/alu.cpp
parentafa9e930255b3c380ad37fccc0767508534bad13 (diff)
downloadqtmips-8f6d939e8d0fdec39c53da65cfb89f288d99eb82.tar.gz
qtmips-8f6d939e8d0fdec39c53da65cfb89f288d99eb82.tar.bz2
qtmips-8f6d939e8d0fdec39c53da65cfb89f288d99eb82.zip
Implement instructions for moving from and to HI and LO registers
Diffstat (limited to 'qtmips_machine/alu.cpp')
-rw-r--r--qtmips_machine/alu.cpp12
1 files changed, 11 insertions, 1 deletions
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));