From 9cf92379d5fcf0076c25dae0935daab446c992cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 30 Aug 2017 21:37:53 +0200 Subject: Initial commit Adding work done so far. --- qtmips_machine/instruction.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 qtmips_machine/instruction.cpp (limited to 'qtmips_machine/instruction.cpp') diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp new file mode 100644 index 0000000..159d443 --- /dev/null +++ b/qtmips_machine/instruction.cpp @@ -0,0 +1,81 @@ +#include "instruction.h" +#include +#include + +InstructionR::InstructionR(std::uint8_t rs, std::uint8_t rd, std::uint8_t rt, std::uint8_t sa) { + this->rs = rs; + this->rd = rd; + this->rt = rt; + this->sa = sa; +} + +// TODO for registers output as register ($0)! + +std::vector InstructionR::to_strs() { + std::vector str; + // Instruction name + str.push_back("unknown"); // unknown instruction, should be replaced by child + + std::stringstream ss; + // Source register + ss << std::hex << (unsigned) this->rs; + str.push_back(ss.str()); + ss.str(""); + // Target register + ss << std::hex << (unsigned) this->rt; + str.push_back(ss.str()); + ss.str(""); + // Destination register + ss << std::hex << (unsigned) this->rd; + str.push_back(ss.str()); + ss.str(""); + // Shift amount + ss << std::hex << (unsigned) this->sa; + str.push_back(ss.str()); + + return str; +} + +InstructionI::InstructionI(std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate) { + this->rs = rs; + this->rt = rt; + this->immediage = immediate; +} + +std::vector InstructionI::to_strs() { + std::vector str; + // Instruction name + str.push_back("unknown"); // unknown instruction, should be replaced by child + + std::stringstream ss; + // Source register + ss << std::hex << (unsigned) this->rs; + str.push_back(ss.str()); + ss.str(""); + // Destination register + ss << std::hex << (unsigned) this->rt; + str.push_back(ss.str()); + ss.str(""); + // Immediate value + ss << std::hex << (unsigned) this->immediage; + str.push_back(ss.str()); + + return str; +} + +InstructionJ::InstructionJ(std::uint32_t address) { + this->address = address; +} + +std::vector InstructionJ::to_strs() { + std::vector str; + // Instruction name + str.push_back("unknown"); // unknown instruction, should be replaced by child + + std::stringstream ss; + // Source register + ss << std::hex << (unsigned) this->address; + str.push_back(ss.str()); + + return str; +} -- cgit v1.2.3