From 45581d3d376e8deed84952cb838ae330549e5241 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 May 2009 23:18:17 +0200 Subject: my cpu design --- ue3/mycpu/instructions.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ue3/mycpu/instructions.h (limited to 'ue3/mycpu/instructions.h') diff --git a/ue3/mycpu/instructions.h b/ue3/mycpu/instructions.h new file mode 100644 index 0000000..ebd1533 --- /dev/null +++ b/ue3/mycpu/instructions.h @@ -0,0 +1,66 @@ +/** + * @module instructions + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief TODO + * @date 10.05.2009 + */ + +#ifndef INSTRUCTIONS_H +#define INSTRUCTIONS_H 1 + +#include "cinstruction.h" +#include "ccpu.h" + +/** + * @class CInstructionInc + * + * TODO + */ +class CInstructionInc + : public CInstruction +{ + public: + /** + * @method CInstruction + * @brief Default ctor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + CInstructionInc() + : CInstruction("inc") + {}; + + /** + * @method ~CInstruction + * @brief Default dtor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + ~CInstructionInc() + {}; + + /* TODO */ + CInstructionInc *factory() + { + return new CInstructionInc; + } + + /* TODO */ + void compile(std::list& params); + + /* TODO */ + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; +}; + +#endif + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3 From 89e202f49b9857dcd3627fbc4e0262125d729bbc Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 04:09:39 +0200 Subject: adding all instructions and displays --- ue3/mycpu/instructions.h | 399 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 373 insertions(+), 26 deletions(-) (limited to 'ue3/mycpu/instructions.h') diff --git a/ue3/mycpu/instructions.h b/ue3/mycpu/instructions.h index ebd1533..8c62e0b 100644 --- a/ue3/mycpu/instructions.h +++ b/ue3/mycpu/instructions.h @@ -20,45 +20,392 @@ class CInstructionInc : public CInstruction { public: - /** - * @method CInstruction - * @brief Default ctor - * @param - - * @return - - * @globalvars none - * @exception none - * @conditions none - */ CInstructionInc() : CInstruction("inc") - {}; - - /** - * @method ~CInstruction - * @brief Default dtor - * @param - - * @return - - * @globalvars none - * @exception none - * @conditions none - */ - ~CInstructionInc() - {}; - - /* TODO */ + {} + CInstructionInc *factory() { return new CInstructionInc; } - /* TODO */ void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; +}; + +/*============================================================================*/ + +/** + * @class CInstructionDec + * + * TODO + */ +class CInstructionDec + : public CInstruction +{ + public: + CInstructionDec() + : CInstruction("dec") + {} + + CInstructionDec *factory() + { + return new CInstructionDec; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; +}; + +/*============================================================================*/ + +/** + * @class CInstructionAdd + * + * TODO + */ +class CInstructionAdd + : public CInstruction +{ + public: + CInstructionAdd() + : CInstruction("add") + {} + + CInstructionAdd *factory() + { + return new CInstructionAdd; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; + unsigned m_regidx3; +}; + +/*============================================================================*/ + +/** + * @class CInstructionSub + * + * TODO + */ +class CInstructionSub + : public CInstruction +{ + public: + CInstructionSub() + : CInstruction("sub") + {} + + CInstructionSub *factory() + { + return new CInstructionSub; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; + unsigned m_regidx3; +}; - /* TODO */ +/*============================================================================*/ + +/** + * @class CInstructionMul + * + * TODO + */ +class CInstructionMul + : public CInstruction +{ + public: + CInstructionMul() + : CInstruction("mul") + {} + + CInstructionMul *factory() + { + return new CInstructionMul; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; + unsigned m_regidx3; +}; + +/*============================================================================*/ + +/** + * @class CInstructionDiv + * + * TODO + */ +class CInstructionDiv + : public CInstruction +{ + public: + CInstructionDiv() + : CInstruction("div") + {} + + CInstructionDiv *factory() + { + return new CInstructionDiv; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; + unsigned m_regidx3; +}; + +/*============================================================================*/ + +/** + * @class CInstructionLoad + * + * TODO + */ +class CInstructionLoad + : public CInstruction +{ + public: + CInstructionLoad() + : CInstruction("load") + {} + + CInstructionLoad *factory() + { + return new CInstructionLoad; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; +}; + +/*============================================================================*/ + +/** + * @class CInstructionStore + * + * TODO + */ +class CInstructionStore + : public CInstruction +{ + public: + CInstructionStore() + : CInstruction("store") + {} + + CInstructionStore *factory() + { + return new CInstructionStore; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; + unsigned m_regidx2; +}; + +/*============================================================================*/ + +/** + * @class CInstructionTest + * + * TODO + */ +class CInstructionTest + : public CInstruction +{ + public: + CInstructionTest() + : CInstruction("test") + {} + + CInstructionTest *factory() + { + return new CInstructionTest; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + unsigned m_regidx1; +}; + +/*============================================================================*/ + +/** + * @class CInstructionLabel + * + * TODO + */ +class CInstructionLabel + : public CInstruction +{ + public: + CInstructionLabel() + : CInstruction("label"), m_label("") + {} + + const bool isLabel() + { + return true; + } + + const std::string getLabelName() + { + return m_label; + } + + CInstructionLabel *factory() + { + return new CInstructionLabel; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + std::string m_label; +}; + +/*============================================================================*/ + +/** + * @class CInstructionJumpA + * + * TODO + */ +class CInstructionJumpA + : public CInstruction +{ + public: + CInstructionJumpA() + : CInstruction("jumpa"), m_addr("") + {} + + CInstructionJumpA *factory() + { + return new CInstructionJumpA; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + std::string m_addr; +}; + +/*============================================================================*/ + +/** + * @class CInstructionJumpZ + * + * TODO + */ +class CInstructionJumpZ + : public CInstruction +{ + public: + CInstructionJumpZ() + : CInstruction("jumpz"), m_addr("") + {} + + CInstructionJumpZ *factory() + { + return new CInstructionJumpZ; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + std::string m_addr; +}; + +/*============================================================================*/ + +/** + * @class CInstructionJumpS + * + * TODO + */ +class CInstructionJumpS + : public CInstruction +{ + public: + CInstructionJumpS() + : CInstruction("jumps"), m_addr("") + {} + + CInstructionJumpS *factory() + { + return new CInstructionJumpS; + } + + void compile(std::list& params); + void execute(CCPU *cpu); + + protected: + std::string m_addr; +}; + +/*============================================================================*/ + +/** + * @class CInstructionWrite + * + * TODO + */ +class CInstructionWrite + : public CInstruction +{ + public: + CInstructionWrite() + : CInstruction("write"), m_dev("") + {} + + CInstructionWrite *factory() + { + return new CInstructionWrite; + } + + void compile(std::list& params); void execute(CCPU *cpu); protected: unsigned m_regidx1; + std::string m_dev; }; #endif -- cgit v1.2.3 From 431bbac5a99abbccf33500e22aa353ec792eff94 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 15:29:51 +0200 Subject: * adding -Wno-long-long to all Makefiles * adding execute operator to cinstruction * added labels map for better performance --- ue3/mycpu/instructions.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'ue3/mycpu/instructions.h') diff --git a/ue3/mycpu/instructions.h b/ue3/mycpu/instructions.h index 8c62e0b..0e4d99c 100644 --- a/ue3/mycpu/instructions.h +++ b/ue3/mycpu/instructions.h @@ -274,29 +274,19 @@ class CInstructionLabel { public: CInstructionLabel() - : CInstruction("label"), m_label("") + : CInstruction("label") {} - const bool isLabel() - { - return true; - } - - const std::string getLabelName() - { - return m_label; - } - CInstructionLabel *factory() { return new CInstructionLabel; } - void compile(std::list& params); - void execute(CCPU *cpu); + void compile(std::list& params) + {} - protected: - std::string m_label; + void execute(CCPU *cpu) + {} }; /*============================================================================*/ -- cgit v1.2.3 From 3c6f886d5a8bfd36c796b963d6e3178ad9577742 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 16:55:17 +0200 Subject: * added documentation (no more TODOs) * added testsuite + testcase * used copyctor instead of assign operator more often --- ue3/mycpu/instructions.h | 57 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) (limited to 'ue3/mycpu/instructions.h') diff --git a/ue3/mycpu/instructions.h b/ue3/mycpu/instructions.h index 0e4d99c..a52b991 100644 --- a/ue3/mycpu/instructions.h +++ b/ue3/mycpu/instructions.h @@ -1,7 +1,7 @@ /** * @module instructions * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) - * @brief TODO + * @brief Implementations of CInstruction * @date 10.05.2009 */ @@ -14,7 +14,9 @@ /** * @class CInstructionInc * - * TODO + * Implementation of assembler command "inc" + * Syntax: inc R1 + * (R1++) */ class CInstructionInc : public CInstruction @@ -41,7 +43,9 @@ class CInstructionInc /** * @class CInstructionDec * - * TODO + * Implementation of assembler command "dec" + * Syntax: dec R1 + * (R1--) */ class CInstructionDec : public CInstruction @@ -68,7 +72,9 @@ class CInstructionDec /** * @class CInstructionAdd * - * TODO + * Implementation of assembler command "add" + * Syntax: add R1, R2, R3 + * (R1 = R2 + R3) */ class CInstructionAdd : public CInstruction @@ -97,7 +103,9 @@ class CInstructionAdd /** * @class CInstructionSub * - * TODO + * Implementation of assembler command "sub" + * Syntax: sub R1, R2, R3 + * (R1 = R2 - R3) */ class CInstructionSub : public CInstruction @@ -126,7 +134,9 @@ class CInstructionSub /** * @class CInstructionMul * - * TODO + * Implementation of assembler command "mul" + * Syntax: mul R1, R2, R3 + * (R1 = R2 * R3) */ class CInstructionMul : public CInstruction @@ -155,7 +165,9 @@ class CInstructionMul /** * @class CInstructionDiv * - * TODO + * Implementation of assembler command "div" + * Syntax: div R1, R2, R3 + * (R1 = R2 / R3) */ class CInstructionDiv : public CInstruction @@ -184,7 +196,9 @@ class CInstructionDiv /** * @class CInstructionLoad * - * TODO + * Implementation of assembler command "load" + * Syntax: load R1, R2 + * (R1 = memory[R2]) */ class CInstructionLoad : public CInstruction @@ -212,7 +226,9 @@ class CInstructionLoad /** * @class CInstructionStore * - * TODO + * Implementation of assembler command "store" + * Syntax: store R1, R2 + * (memory[R2] = R1) */ class CInstructionStore : public CInstruction @@ -240,7 +256,9 @@ class CInstructionStore /** * @class CInstructionTest * - * TODO + * Implementation of assembler command "test" + * Syntax: test R1 + * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) */ class CInstructionTest : public CInstruction @@ -267,7 +285,8 @@ class CInstructionTest /** * @class CInstructionLabel * - * TODO + * Implementation of assembler command "label" + * Syntax: label name: */ class CInstructionLabel : public CInstruction @@ -294,7 +313,9 @@ class CInstructionLabel /** * @class CInstructionJumpA * - * TODO + * Implementation of assembler command "jumpa" + * Syntax: jumpa labelname + * (jump to labelname) */ class CInstructionJumpA : public CInstruction @@ -321,7 +342,9 @@ class CInstructionJumpA /** * @class CInstructionJumpZ * - * TODO + * Implementation of assembler command "jumpz" + * Syntax: jumpz labelname + * (jump to labelname if zeroflag) */ class CInstructionJumpZ : public CInstruction @@ -348,7 +371,9 @@ class CInstructionJumpZ /** * @class CInstructionJumpS * - * TODO + * Implementation of assembler command "jumps" + * Syntax: jumps labelname + * (jump to labelname if signflag) */ class CInstructionJumpS : public CInstruction @@ -375,7 +400,9 @@ class CInstructionJumpS /** * @class CInstructionWrite * - * TODO + * Implementation of assembler command "write" + * Syntax: write DEV, R1 + * (write R1 to DEV, which is a name of a display) */ class CInstructionWrite : public CInstruction -- cgit v1.2.3 From 67e99a217bd88a289d997b73f3e7cae6019bc22f Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 17:01:15 +0200 Subject: fixing doxygen documentation --- ue3/mycpu/instructions.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ue3/mycpu/instructions.h') diff --git a/ue3/mycpu/instructions.h b/ue3/mycpu/instructions.h index a52b991..4c36562 100644 --- a/ue3/mycpu/instructions.h +++ b/ue3/mycpu/instructions.h @@ -35,6 +35,7 @@ class CInstructionInc void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; }; @@ -64,6 +65,7 @@ class CInstructionDec void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; }; @@ -93,8 +95,11 @@ class CInstructionAdd void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; + /** register number */ unsigned m_regidx3; }; @@ -124,8 +129,11 @@ class CInstructionSub void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; + /** register number */ unsigned m_regidx3; }; @@ -155,8 +163,11 @@ class CInstructionMul void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; + /** register number */ unsigned m_regidx3; }; @@ -186,8 +197,11 @@ class CInstructionDiv void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; + /** register number */ unsigned m_regidx3; }; @@ -217,7 +231,9 @@ class CInstructionLoad void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; }; @@ -247,7 +263,9 @@ class CInstructionStore void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** register number */ unsigned m_regidx2; }; @@ -277,6 +295,7 @@ class CInstructionTest void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; }; @@ -334,6 +353,7 @@ class CInstructionJumpA void execute(CCPU *cpu); protected: + /** labelname */ std::string m_addr; }; @@ -363,6 +383,7 @@ class CInstructionJumpZ void execute(CCPU *cpu); protected: + /** labelname */ std::string m_addr; }; @@ -392,6 +413,7 @@ class CInstructionJumpS void execute(CCPU *cpu); protected: + /** labelname */ std::string m_addr; }; @@ -421,7 +443,9 @@ class CInstructionWrite void execute(CCPU *cpu); protected: + /** register number */ unsigned m_regidx1; + /** device name */ std::string m_dev; }; -- cgit v1.2.3