aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/instruction.h
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine/instruction.h')
-rw-r--r--qtmips_machine/instruction.h66
1 files changed, 16 insertions, 50 deletions
diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h
index 8c5ede9..3b76fba 100644
--- a/qtmips_machine/instruction.h
+++ b/qtmips_machine/instruction.h
@@ -2,64 +2,30 @@
#define INSTRUCTION_H
#include <qstring.h>
-#include <qvector.h>
-#include "registers.h"
-#include "memory.h"
-
-enum InstructionState {
- IS_FETCH,
- IS_DECODE,
- IS_EXECUTE,
- IS_MEMORY,
- IS_WRITE_BACK,
-};
class Instruction {
public:
- Instruction();
+ Instruction(std::uint32_t inst);
+ Instruction(std::uint8_t opcode, std::uint8_t rs, std::uint8_t rt, std::uint8_t rd, std::uint8_t shamt, std::uint8_t funct); // Type R
+ Instruction(std::uint8_t opcode, std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate); // Type I
+ Instruction(std::uint8_t opcode, std::uint32_t address); // Type J
- // TODO return some info for forwarding, stall, flush
- virtual void decode(Registers *regs); // Read and prepare instructions
- virtual void execute(); // ALU operations
- virtual void memory(Memory *mem); // Read or write to memory
- virtual void write_back(Registers *regs); // Write results to registers
+ QString to_str();
- enum InstructionState state();
- bool running();
- bool done();
+ std::uint8_t opcode() const;
+ std::uint8_t rs() const;
+ std::uint8_t rt() const;
+ std::uint8_t rd() const;
+ std::uint8_t shamt() const;
+ std::uint8_t funct() const;
+ std::uint16_t immediate() const;
+ std::uint32_t address() const;
+ std::uint32_t data() const;
- virtual QVector<QString> to_strs() = 0; // Returns all fields of instructions in string
+ bool operator ==(const Instruction &c) const;
private:
- enum InstructionState st;
-};
-
-class InstructionR : public Instruction {
-public:
- InstructionR(std::uint8_t rs, std::uint8_t rd, std::uint8_t rt, std::uint8_t sa);
-
- QVector<QString> to_strs();
-protected:
- std::uint8_t rs, rd, rt, sa;
-};
-
-class InstructionI : public Instruction {
-public:
- InstructionI(std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate);
-
- QVector<QString> to_strs();
-protected:
- std::uint8_t rs, rt;
- std::uint16_t immediate;
-};
-
-class InstructionJ : public Instruction {
-public:
- InstructionJ(std::uint32_t address);
-
- QVector<QString> to_strs();
-protected:
- std::uint32_t address;
+ std::uint32_t dt;
};
#endif // INSTRUCTION_H