diff options
author | Karel Kočí <cynerd@email.cz> | 2017-08-30 23:29:14 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-08-30 23:29:14 +0200 |
commit | c975257cef23d254b1fa9290474268a61509e954 (patch) | |
tree | d7f219fa9fcb5a54cc9ccfc5aa692643ea968562 /qtmips_machine/instruction.cpp | |
parent | 83e8593d9e36725d2bfb9d450da451e47a93f349 (diff) | |
download | qtmips-c975257cef23d254b1fa9290474268a61509e954.tar.gz qtmips-c975257cef23d254b1fa9290474268a61509e954.tar.bz2 qtmips-c975257cef23d254b1fa9290474268a61509e954.zip |
Some to_string_hex cleanups
Diffstat (limited to 'qtmips_machine/instruction.cpp')
-rw-r--r-- | qtmips_machine/instruction.cpp | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp index 159d443..c5d5345 100644 --- a/qtmips_machine/instruction.cpp +++ b/qtmips_machine/instruction.cpp @@ -1,6 +1,7 @@ #include "instruction.h" #include <sstream> #include <iostream> +#include "utils.h" InstructionR::InstructionR(std::uint8_t rs, std::uint8_t rd, std::uint8_t rt, std::uint8_t sa) { this->rs = rs; @@ -16,22 +17,14 @@ std::vector<std::string> InstructionR::to_strs() { // 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(""); + str.push_back(to_string_hex((unsigned)this->rs)); // Target register - ss << std::hex << (unsigned) this->rt; - str.push_back(ss.str()); - ss.str(""); + str.push_back(to_string_hex((unsigned)this->rt)); // Destination register - ss << std::hex << (unsigned) this->rd; - str.push_back(ss.str()); - ss.str(""); + str.push_back(to_string_hex((unsigned)this->rd)); // Shift amount - ss << std::hex << (unsigned) this->sa; - str.push_back(ss.str()); + str.push_back(to_string_hex((unsigned)this->sa)); return str; } @@ -39,7 +32,7 @@ std::vector<std::string> InstructionR::to_strs() { InstructionI::InstructionI(std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate) { this->rs = rs; this->rt = rt; - this->immediage = immediate; + this->immediate = immediate; } std::vector<std::string> InstructionI::to_strs() { @@ -47,18 +40,12 @@ std::vector<std::string> InstructionI::to_strs() { // 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(""); + str.push_back(to_string_hex((unsigned)this->rs)); + // Target register + str.push_back(to_string_hex((unsigned)this->rt)); // Immediate value - ss << std::hex << (unsigned) this->immediage; - str.push_back(ss.str()); + str.push_back(to_string_hex((unsigned)this->immediate)); return str; } @@ -74,8 +61,7 @@ std::vector<std::string> InstructionJ::to_strs() { std::stringstream ss; // Source register - ss << std::hex << (unsigned) this->address; - str.push_back(ss.str()); + str.push_back(to_string_hex((unsigned)this->address)); return str; } |