diff options
author | Karel Kočí <cynerd@email.cz> | 2017-08-30 21:37:53 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-08-30 21:42:02 +0200 |
commit | 9cf92379d5fcf0076c25dae0935daab446c992cd (patch) | |
tree | dd09a2e996db1e5a8117f01bec76f1e93eaca6e1 /qtmips_machine/instruction.cpp | |
download | qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.gz qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.bz2 qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.zip |
Initial commit
Adding work done so far.
Diffstat (limited to 'qtmips_machine/instruction.cpp')
-rw-r--r-- | qtmips_machine/instruction.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
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 <sstream> +#include <iostream> + +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<std::string> InstructionR::to_strs() { + std::vector<std::string> 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<std::string> InstructionI::to_strs() { + std::vector<std::string> 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<std::string> InstructionJ::to_strs() { + std::vector<std::string> 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; +} |