diff options
author | Karel Kočí <cynerd@email.cz> | 2017-09-05 00:31:13 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-09-05 00:31:13 +0200 |
commit | 04ea2670be26291a17808bd704ce3549795953a0 (patch) | |
tree | 3beb72850745b014eb3ed5eb2e88bfe565c8d2df /qtmips_machine/instructions | |
parent | ccf2283819a631cec62ceaec233ee845f28d59d8 (diff) | |
download | qtmips-04ea2670be26291a17808bd704ce3549795953a0.tar.gz qtmips-04ea2670be26291a17808bd704ce3549795953a0.tar.bz2 qtmips-04ea2670be26291a17808bd704ce3549795953a0.zip |
Add some more instructions to be decoded and arithmetic I test
Diffstat (limited to 'qtmips_machine/instructions')
-rw-r--r-- | qtmips_machine/instructions/arithmetic.cpp | 90 | ||||
-rw-r--r-- | qtmips_machine/instructions/arithmetic.h | 14 |
2 files changed, 103 insertions, 1 deletions
diff --git a/qtmips_machine/instructions/arithmetic.cpp b/qtmips_machine/instructions/arithmetic.cpp index a620436..f3cad86 100644 --- a/qtmips_machine/instructions/arithmetic.cpp +++ b/qtmips_machine/instructions/arithmetic.cpp @@ -5,6 +5,58 @@ InstructionArithmetic::InstructionArithmetic(enum InstructionArithmeticT type, s this->type = type; } +void InstructionArithmetic::decode(Registers *regs) { + Instruction::decode(regs); + this->rs_d = regs->read_gp(this->rs); + this->rd_d = regs->read_gp(this->rd); +} + +void InstructionArithmetic::execute() { + Instruction::execute(); + switch (this->type) { + case IAT_ADD: + this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d + (std::int32_t)this->rd_d); + break; + case IAT_ADDU: + this->rt_d = this->rs_d + this->rd_d; + break; + case IAT_SUB: + this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d - (std::int32_t)this->rd_d); + break; + case IAT_SUBU: + this->rt_d = this->rs_d - this->rd_d; + break; + case IAT_AND: + this->rt_d = this->rs_d & this->rd_d; + break; + case IAT_OR: + this->rt_d = this->rs_d | this->rd_d; + break; + case IAT_XOR: + this->rt_d = this->rs_d ^ this->rd_d; + break; + case IAT_NOR: + // TODO + break; + case IAT_SLT: + // TODO + break; + case IAT_SLTU: + // TODO + break; + } +} + +void InstructionArithmetic::memory(Memory *mem) { + Instruction::memory(mem); + // pass +} + +void InstructionArithmetic::write_back(Registers *regs) { + Instruction::write_back(regs); + regs->write_gp(this->rt, this->rt_d); +} + QVector<QString> InstructionArithmetic::to_strs() { QVector<QString> str = this->InstructionR::to_strs(); str.erase(str.begin() + 4); // Drop sa field @@ -51,6 +103,42 @@ InstructionArithmeticImmediate::InstructionArithmeticImmediate(enum InstructionA this->type = type; } +void InstructionArithmeticImmediate::decode(Registers *regs) { + Instruction::decode(regs); + this->rs_d = regs->read_gp(this->rs); +} + +void InstructionArithmeticImmediate::execute() { + Instruction::execute(); + switch (this->type) { + case IAT_ADDI: + this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d + (std::int32_t)this->immediate); + break; + case IAT_ADDIU: + this->rt_d = this->rs_d + this->immediate; + break; + case IAT_ANDI: + this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d - (std::int32_t)this->immediate); + break; + case IAT_ORI: + this->rt_d = this->rs_d - this->immediate; + break; + case IAT_XORI: + this->rt_d = this->rs_d & this->immediate; + break; + } +} + +void InstructionArithmeticImmediate::memory(Memory *mem) { + Instruction::memory(mem); + // pass +} + +void InstructionArithmeticImmediate::write_back(Registers *regs) { + Instruction::write_back(regs); + regs->write_gp(this->rt, this->rt_d); +} + QVector<QString> InstructionArithmeticImmediate::to_strs() { QVector<QString> str = this->InstructionI::to_strs(); switch (this->type) { @@ -76,7 +164,7 @@ QVector<QString> InstructionArithmeticImmediate::to_strs() { str[0] = "sltiu"; break; case IAT_LUI: - str[0] = "lu"; + str[0] = "lui"; break; default: // TODO different exception diff --git a/qtmips_machine/instructions/arithmetic.h b/qtmips_machine/instructions/arithmetic.h index 19f1df5..185ed95 100644 --- a/qtmips_machine/instructions/arithmetic.h +++ b/qtmips_machine/instructions/arithmetic.h @@ -19,9 +19,16 @@ enum InstructionArithmeticT { class InstructionArithmetic : public InstructionR { public: InstructionArithmetic(enum InstructionArithmeticT type, std::uint8_t rs, std::uint8_t rd, std::uint8_t rt); + + void decode(Registers *regs); + void execute(); + void memory(Memory *mem); + void write_back(Registers *regs); + QVector<QString> to_strs(); private: enum InstructionArithmeticT type; + std::uint32_t rs_d, rd_d, rt_d; }; enum InstructionArithmeticImmediateT { @@ -38,9 +45,16 @@ enum InstructionArithmeticImmediateT { class InstructionArithmeticImmediate : public InstructionI { public: InstructionArithmeticImmediate(enum InstructionArithmeticImmediateT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t value); + + void decode(Registers *regs); + void execute(); + void memory(Memory *mem); + void write_back(Registers *regs); + QVector<QString> to_strs(); private: enum InstructionArithmeticImmediateT type; + std::uint32_t rs_d, rt_d; }; #endif // ARITHMETIC_H |