diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-13 16:55:17 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-13 16:55:17 +0200 |
| commit | 3c6f886d5a8bfd36c796b963d6e3178ad9577742 (patch) | |
| tree | 7a65d184e66c810777d18ea208931910c91b7e43 | |
| parent | 431bbac5a99abbccf33500e22aa353ec792eff94 (diff) | |
| download | ooprog-3c6f886d5a8bfd36c796b963d6e3178ad9577742.tar.gz ooprog-3c6f886d5a8bfd36c796b963d6e3178ad9577742.tar.bz2 ooprog-3c6f886d5a8bfd36c796b963d6e3178ad9577742.zip | |
* added documentation (no more TODOs)
* added testsuite + testcase
* used copyctor instead of assign operator more often
| -rw-r--r-- | .hgignore | 1 | ||||
| -rw-r--r-- | ue3/mycpu/ccpu.cpp | 3 | ||||
| -rw-r--r-- | ue3/mycpu/ccpu.h | 6 | ||||
| -rw-r--r-- | ue3/mycpu/cdisplay.h | 9 | ||||
| -rw-r--r-- | ue3/mycpu/cinstruction.cpp | 4 | ||||
| -rw-r--r-- | ue3/mycpu/cinstruction.h | 6 | ||||
| -rw-r--r-- | ue3/mycpu/cprogram.cpp | 6 | ||||
| -rw-r--r-- | ue3/mycpu/cprogram.h | 5 | ||||
| -rw-r--r-- | ue3/mycpu/displays.h | 8 | ||||
| -rw-r--r-- | ue3/mycpu/instructions.cpp | 6 | ||||
| -rw-r--r-- | ue3/mycpu/instructions.h | 57 | ||||
| -rw-r--r-- | ue3/mycpu/mycpu.cpp | 25 | ||||
| -rwxr-xr-x | ue3/mycpu/test/test.sh | 40 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_memory | 1 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_output | 19 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_program | 13 |
16 files changed, 161 insertions, 48 deletions
| @@ -5,6 +5,7 @@ syntax: glob | |||
| 5 | *.so | 5 | *.so |
| 6 | *.swp | 6 | *.swp |
| 7 | *~ | 7 | *~ |
| 8 | tmpfile | ||
| 8 | ue1/imgsynth/imgsynth | 9 | ue1/imgsynth/imgsynth |
| 9 | ue2/imgsynth/test/*_out* | 10 | ue2/imgsynth/test/*_out* |
| 10 | ue2/imgsynth2/imgsynth2 | 11 | ue2/imgsynth2/imgsynth2 |
diff --git a/ue3/mycpu/ccpu.cpp b/ue3/mycpu/ccpu.cpp index 16209e2..af86200 100644 --- a/ue3/mycpu/ccpu.cpp +++ b/ue3/mycpu/ccpu.cpp | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module ccpu | 2 | * @module ccpu |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief CPU implementation. Used as a container for memory and instructions. |
| 5 | * Implements an run method to execute the program (= the instructions). | ||
| 5 | * @date 10.05.2009 | 6 | * @date 10.05.2009 |
| 6 | */ | 7 | */ |
| 7 | 8 | ||
diff --git a/ue3/mycpu/ccpu.h b/ue3/mycpu/ccpu.h index 01c897f..05b5c03 100644 --- a/ue3/mycpu/ccpu.h +++ b/ue3/mycpu/ccpu.h | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module ccpu | 2 | * @module ccpu |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief CPU implementation. Used as a container for memory and instructions. |
| 5 | * Implements a run method to execute the program (= the instructions). | ||
| 5 | * @date 10.05.2009 | 6 | * @date 10.05.2009 |
| 6 | */ | 7 | */ |
| 7 | 8 | ||
| @@ -18,7 +19,8 @@ | |||
| 18 | /** | 19 | /** |
| 19 | * @class CCPU | 20 | * @class CCPU |
| 20 | * | 21 | * |
| 21 | * TODO | 22 | * CPU implementation. Used as a container for memory and instructions. |
| 23 | * Implements a run method to execute the program (= the instructions). | ||
| 22 | */ | 24 | */ |
| 23 | class CCPU | 25 | class CCPU |
| 24 | { | 26 | { |
diff --git a/ue3/mycpu/cdisplay.h b/ue3/mycpu/cdisplay.h index ed9b84d..c2a84a6 100644 --- a/ue3/mycpu/cdisplay.h +++ b/ue3/mycpu/cdisplay.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cdisplay | 2 | * @module cdisplay |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Abstract class for displays |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -11,7 +11,7 @@ | |||
| 11 | /** | 11 | /** |
| 12 | * @class CDisplay | 12 | * @class CDisplay |
| 13 | * | 13 | * |
| 14 | * TODO | 14 | * Abstract class for displays |
| 15 | */ | 15 | */ |
| 16 | class CDisplay | 16 | class CDisplay |
| 17 | { | 17 | { |
| @@ -26,9 +26,8 @@ class CDisplay | |||
| 26 | * @conditions none | 26 | * @conditions none |
| 27 | */ | 27 | */ |
| 28 | CDisplay(std::string name) | 28 | CDisplay(std::string name) |
| 29 | { | 29 | : m_name(name) |
| 30 | m_name = name; | 30 | {} |
| 31 | } | ||
| 32 | 31 | ||
| 33 | /** | 32 | /** |
| 34 | * @method ~CDisplay | 33 | * @method ~CDisplay |
diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp index 57acd5f..5c1bd5c 100644 --- a/ue3/mycpu/cinstruction.cpp +++ b/ue3/mycpu/cinstruction.cpp | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cinstruction | 2 | * @module cinstruction |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Abstract class for displays |
| 5 | * @date 10.05.2009 | 5 | * @date 13.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <sstream> | 8 | #include <sstream> |
diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h index 40e9ddc..942d8cf 100644 --- a/ue3/mycpu/cinstruction.h +++ b/ue3/mycpu/cinstruction.h | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cinstruction | 2 | * @module cinstruction |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Abstract class for displays |
| 5 | * @date 10.05.2009 | 5 | * @date 13.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef CINSTRUCTION_H | 8 | #ifndef CINSTRUCTION_H |
| @@ -17,7 +17,7 @@ class CCPU; | |||
| 17 | /** | 17 | /** |
| 18 | * @class CInstruction | 18 | * @class CInstruction |
| 19 | * | 19 | * |
| 20 | * TODO | 20 | * Abstract class for displays |
| 21 | */ | 21 | */ |
| 22 | class CInstruction | 22 | class CInstruction |
| 23 | { | 23 | { |
diff --git a/ue3/mycpu/cprogram.cpp b/ue3/mycpu/cprogram.cpp index f904bce..1a450f5 100644 --- a/ue3/mycpu/cprogram.cpp +++ b/ue3/mycpu/cprogram.cpp | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cprogram | 2 | * @module cprogram |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief CProgram extends std::vector and adds a method for parsing programfile |
| 5 | * @date 12.05.2009 | 5 | * @date 12.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -75,7 +75,7 @@ void CProgram::compile(std::istream& in) | |||
| 75 | 75 | ||
| 76 | /* get instruction name */ | 76 | /* get instruction name */ |
| 77 | size_t pos = line.find_first_of(' '); | 77 | size_t pos = line.find_first_of(' '); |
| 78 | string instrname = line.substr(0, pos); | 78 | string instrname(line.substr(0, pos)); |
| 79 | 79 | ||
| 80 | /* search and create instruction */ | 80 | /* search and create instruction */ |
| 81 | CInstruction *instrptr = NULL; | 81 | CInstruction *instrptr = NULL; |
| @@ -112,7 +112,7 @@ void CProgram::compile(std::istream& in) | |||
| 112 | { | 112 | { |
| 113 | if (instrparams.size() != 1) | 113 | if (instrparams.size() != 1) |
| 114 | throw runtime_error("Invalid paramater count - must be 1"); | 114 | throw runtime_error("Invalid paramater count - must be 1"); |
| 115 | string label = instrparams.front(); | 115 | string label(instrparams.front()); |
| 116 | if (label.length() < 2 || label[ label.length() - 1] != ':') | 116 | if (label.length() < 2 || label[ label.length() - 1] != ':') |
| 117 | throw runtime_error("Label has invalid syntax"); | 117 | throw runtime_error("Label has invalid syntax"); |
| 118 | m_labels[ label.substr(0, label.length() - 1) ] = size(); | 118 | m_labels[ label.substr(0, label.length() - 1) ] = size(); |
diff --git a/ue3/mycpu/cprogram.h b/ue3/mycpu/cprogram.h index c145832..27e7647 100644 --- a/ue3/mycpu/cprogram.h +++ b/ue3/mycpu/cprogram.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module cprogram | 2 | * @module cprogram |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief CProgram extends std::vector and adds a method for parsing programfile |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -16,7 +16,8 @@ | |||
| 16 | /** | 16 | /** |
| 17 | * @class CProgram | 17 | * @class CProgram |
| 18 | * | 18 | * |
| 19 | * TODO | 19 | * CProgram extends std::vector and adds a method for parsing |
| 20 | * programfile. This adds instances of CInstruction to CProgram itself. | ||
| 20 | */ | 21 | */ |
| 21 | class CProgram | 22 | class CProgram |
| 22 | : public std::vector<CInstruction *> | 23 | : public std::vector<CInstruction *> |
diff --git a/ue3/mycpu/displays.h b/ue3/mycpu/displays.h index f7adbdb..87b9408 100644 --- a/ue3/mycpu/displays.h +++ b/ue3/mycpu/displays.h | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module displays | 2 | * @module displays |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Implementations of CDisplay |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -14,7 +14,8 @@ | |||
| 14 | /** | 14 | /** |
| 15 | * @class CDisplayWDEZ | 15 | * @class CDisplayWDEZ |
| 16 | * | 16 | * |
| 17 | * TODO | 17 | * Implementation of CDisplay |
| 18 | * Prints CDat to stdout as decimal | ||
| 18 | */ | 19 | */ |
| 19 | class CDisplayWDEZ | 20 | class CDisplayWDEZ |
| 20 | : public CDisplay | 21 | : public CDisplay |
| @@ -35,7 +36,8 @@ class CDisplayWDEZ | |||
| 35 | /** | 36 | /** |
| 36 | * @class CDisplayWHEX | 37 | * @class CDisplayWHEX |
| 37 | * | 38 | * |
| 38 | * TODO | 39 | * Implementation of CDisplay |
| 40 | * Prints CDat to stdout as decimal | ||
| 39 | */ | 41 | */ |
| 40 | class CDisplayWHEX | 42 | class CDisplayWHEX |
| 41 | : public CDisplay | 43 | : public CDisplay |
diff --git a/ue3/mycpu/instructions.cpp b/ue3/mycpu/instructions.cpp index a6ac611..c2ce096 100644 --- a/ue3/mycpu/instructions.cpp +++ b/ue3/mycpu/instructions.cpp | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module instructions | 2 | * @module instructions |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Implementations of CInstruction |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -162,7 +162,7 @@ void CInstructionLoad::execute(CCPU *cpu) | |||
| 162 | { | 162 | { |
| 163 | checkRegister(cpu, m_regidx1); | 163 | checkRegister(cpu, m_regidx1); |
| 164 | checkRegister(cpu, m_regidx2); | 164 | checkRegister(cpu, m_regidx2); |
| 165 | CDat val = cpu->getRegisters()[ m_regidx2 ]; | 165 | CDat val(cpu->getRegisters()[ m_regidx2 ]); |
| 166 | cpu->getRegisters()[ m_regidx1 ] = (*cpu->getMemory())[ val ]; | 166 | cpu->getRegisters()[ m_regidx1 ] = (*cpu->getMemory())[ val ]; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| @@ -184,7 +184,7 @@ void CInstructionStore::execute(CCPU *cpu) | |||
| 184 | { | 184 | { |
| 185 | checkRegister(cpu, m_regidx1); | 185 | checkRegister(cpu, m_regidx1); |
| 186 | checkRegister(cpu, m_regidx2); | 186 | checkRegister(cpu, m_regidx2); |
| 187 | CDat val = cpu->getRegisters()[ m_regidx2 ]; | 187 | CDat val(cpu->getRegisters()[ m_regidx2 ]); |
| 188 | (*cpu->getMemory())[ val ] = cpu->getRegisters()[ m_regidx1 ]; | 188 | (*cpu->getMemory())[ val ] = cpu->getRegisters()[ m_regidx1 ]; |
| 189 | } | 189 | } |
| 190 | 190 | ||
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 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module instructions | 2 | * @module instructions |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief Implementations of CInstruction |
| 5 | * @date 10.05.2009 | 5 | * @date 10.05.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| @@ -14,7 +14,9 @@ | |||
| 14 | /** | 14 | /** |
| 15 | * @class CInstructionInc | 15 | * @class CInstructionInc |
| 16 | * | 16 | * |
| 17 | * TODO | 17 | * Implementation of assembler command "inc" |
| 18 | * Syntax: inc R1 | ||
| 19 | * (R1++) | ||
| 18 | */ | 20 | */ |
| 19 | class CInstructionInc | 21 | class CInstructionInc |
| 20 | : public CInstruction | 22 | : public CInstruction |
| @@ -41,7 +43,9 @@ class CInstructionInc | |||
| 41 | /** | 43 | /** |
| 42 | * @class CInstructionDec | 44 | * @class CInstructionDec |
| 43 | * | 45 | * |
| 44 | * TODO | 46 | * Implementation of assembler command "dec" |
| 47 | * Syntax: dec R1 | ||
| 48 | * (R1--) | ||
| 45 | */ | 49 | */ |
| 46 | class CInstructionDec | 50 | class CInstructionDec |
| 47 | : public CInstruction | 51 | : public CInstruction |
| @@ -68,7 +72,9 @@ class CInstructionDec | |||
| 68 | /** | 72 | /** |
| 69 | * @class CInstructionAdd | 73 | * @class CInstructionAdd |
| 70 | * | 74 | * |
| 71 | * TODO | 75 | * Implementation of assembler command "add" |
| 76 | * Syntax: add R1, R2, R3 | ||
| 77 | * (R1 = R2 + R3) | ||
| 72 | */ | 78 | */ |
| 73 | class CInstructionAdd | 79 | class CInstructionAdd |
| 74 | : public CInstruction | 80 | : public CInstruction |
| @@ -97,7 +103,9 @@ class CInstructionAdd | |||
| 97 | /** | 103 | /** |
| 98 | * @class CInstructionSub | 104 | * @class CInstructionSub |
| 99 | * | 105 | * |
| 100 | * TODO | 106 | * Implementation of assembler command "sub" |
| 107 | * Syntax: sub R1, R2, R3 | ||
| 108 | * (R1 = R2 - R3) | ||
| 101 | */ | 109 | */ |
| 102 | class CInstructionSub | 110 | class CInstructionSub |
| 103 | : public CInstruction | 111 | : public CInstruction |
| @@ -126,7 +134,9 @@ class CInstructionSub | |||
| 126 | /** | 134 | /** |
| 127 | * @class CInstructionMul | 135 | * @class CInstructionMul |
| 128 | * | 136 | * |
| 129 | * TODO | 137 | * Implementation of assembler command "mul" |
| 138 | * Syntax: mul R1, R2, R3 | ||
| 139 | * (R1 = R2 * R3) | ||
| 130 | */ | 140 | */ |
| 131 | class CInstructionMul | 141 | class CInstructionMul |
| 132 | : public CInstruction | 142 | : public CInstruction |
| @@ -155,7 +165,9 @@ class CInstructionMul | |||
| 155 | /** | 165 | /** |
| 156 | * @class CInstructionDiv | 166 | * @class CInstructionDiv |
| 157 | * | 167 | * |
| 158 | * TODO | 168 | * Implementation of assembler command "div" |
| 169 | * Syntax: div R1, R2, R3 | ||
| 170 | * (R1 = R2 / R3) | ||
| 159 | */ | 171 | */ |
| 160 | class CInstructionDiv | 172 | class CInstructionDiv |
| 161 | : public CInstruction | 173 | : public CInstruction |
| @@ -184,7 +196,9 @@ class CInstructionDiv | |||
| 184 | /** | 196 | /** |
| 185 | * @class CInstructionLoad | 197 | * @class CInstructionLoad |
| 186 | * | 198 | * |
| 187 | * TODO | 199 | * Implementation of assembler command "load" |
| 200 | * Syntax: load R1, R2 | ||
| 201 | * (R1 = memory[R2]) | ||
| 188 | */ | 202 | */ |
| 189 | class CInstructionLoad | 203 | class CInstructionLoad |
| 190 | : public CInstruction | 204 | : public CInstruction |
| @@ -212,7 +226,9 @@ class CInstructionLoad | |||
| 212 | /** | 226 | /** |
| 213 | * @class CInstructionStore | 227 | * @class CInstructionStore |
| 214 | * | 228 | * |
| 215 | * TODO | 229 | * Implementation of assembler command "store" |
| 230 | * Syntax: store R1, R2 | ||
| 231 | * (memory[R2] = R1) | ||
| 216 | */ | 232 | */ |
| 217 | class CInstructionStore | 233 | class CInstructionStore |
| 218 | : public CInstruction | 234 | : public CInstruction |
| @@ -240,7 +256,9 @@ class CInstructionStore | |||
| 240 | /** | 256 | /** |
| 241 | * @class CInstructionTest | 257 | * @class CInstructionTest |
| 242 | * | 258 | * |
| 243 | * TODO | 259 | * Implementation of assembler command "test" |
| 260 | * Syntax: test R1 | ||
| 261 | * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) | ||
| 244 | */ | 262 | */ |
| 245 | class CInstructionTest | 263 | class CInstructionTest |
| 246 | : public CInstruction | 264 | : public CInstruction |
| @@ -267,7 +285,8 @@ class CInstructionTest | |||
| 267 | /** | 285 | /** |
| 268 | * @class CInstructionLabel | 286 | * @class CInstructionLabel |
| 269 | * | 287 | * |
| 270 | * TODO | 288 | * Implementation of assembler command "label" |
| 289 | * Syntax: label name: | ||
| 271 | */ | 290 | */ |
| 272 | class CInstructionLabel | 291 | class CInstructionLabel |
| 273 | : public CInstruction | 292 | : public CInstruction |
| @@ -294,7 +313,9 @@ class CInstructionLabel | |||
| 294 | /** | 313 | /** |
| 295 | * @class CInstructionJumpA | 314 | * @class CInstructionJumpA |
| 296 | * | 315 | * |
| 297 | * TODO | 316 | * Implementation of assembler command "jumpa" |
| 317 | * Syntax: jumpa labelname | ||
| 318 | * (jump to labelname) | ||
| 298 | */ | 319 | */ |
| 299 | class CInstructionJumpA | 320 | class CInstructionJumpA |
| 300 | : public CInstruction | 321 | : public CInstruction |
| @@ -321,7 +342,9 @@ class CInstructionJumpA | |||
| 321 | /** | 342 | /** |
| 322 | * @class CInstructionJumpZ | 343 | * @class CInstructionJumpZ |
| 323 | * | 344 | * |
| 324 | * TODO | 345 | * Implementation of assembler command "jumpz" |
| 346 | * Syntax: jumpz labelname | ||
| 347 | * (jump to labelname if zeroflag) | ||
| 325 | */ | 348 | */ |
| 326 | class CInstructionJumpZ | 349 | class CInstructionJumpZ |
| 327 | : public CInstruction | 350 | : public CInstruction |
| @@ -348,7 +371,9 @@ class CInstructionJumpZ | |||
| 348 | /** | 371 | /** |
| 349 | * @class CInstructionJumpS | 372 | * @class CInstructionJumpS |
| 350 | * | 373 | * |
| 351 | * TODO | 374 | * Implementation of assembler command "jumps" |
| 375 | * Syntax: jumps labelname | ||
| 376 | * (jump to labelname if signflag) | ||
| 352 | */ | 377 | */ |
| 353 | class CInstructionJumpS | 378 | class CInstructionJumpS |
| 354 | : public CInstruction | 379 | : public CInstruction |
| @@ -375,7 +400,9 @@ class CInstructionJumpS | |||
| 375 | /** | 400 | /** |
| 376 | * @class CInstructionWrite | 401 | * @class CInstructionWrite |
| 377 | * | 402 | * |
| 378 | * TODO | 403 | * Implementation of assembler command "write" |
| 404 | * Syntax: write DEV, R1 | ||
| 405 | * (write R1 to DEV, which is a name of a display) | ||
| 379 | */ | 406 | */ |
| 380 | class CInstructionWrite | 407 | class CInstructionWrite |
| 381 | : public CInstruction | 408 | : public CInstruction |
diff --git a/ue3/mycpu/mycpu.cpp b/ue3/mycpu/mycpu.cpp index 08861a4..b25e721 100644 --- a/ue3/mycpu/mycpu.cpp +++ b/ue3/mycpu/mycpu.cpp | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * @module mycpu | 2 | * @module mycpu |
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) |
| 4 | * @brief TODO | 4 | * @brief mycpu executes a programfile (in simple assembler) by parsing the |
| 5 | * @date 11.05.2009 | 5 | * programfile first. This creates a vector of instructions, which will |
| 6 | * be executed in linear order (except jumps) afterwards. In order to | ||
| 7 | * initialize the memory of the cpu before execution an optional | ||
| 8 | * memoryfile can be passed as commandline option. | ||
| 9 | * @date 13.05.2009 | ||
| 6 | * @par Exercise | 10 | * @par Exercise |
| 7 | * 3 | 11 | * 4 |
| 8 | */ | 12 | */ |
| 9 | 13 | ||
| 10 | #include <boost/program_options.hpp> | 14 | #include <boost/program_options.hpp> |
| @@ -29,7 +33,11 @@ namespace po = boost::program_options; | |||
| 29 | * @exception none | 33 | * @exception none |
| 30 | * @conditions none | 34 | * @conditions none |
| 31 | * | 35 | * |
| 32 | * TODO | 36 | * parse commandline options, create and initialize memory, |
| 37 | * create cprogram instance, which parses the programfile and | ||
| 38 | * execute CCPU::run() | ||
| 39 | * On error print error message to stderr. | ||
| 40 | * Unknown commandline options will print a usage message. | ||
| 33 | */ | 41 | */ |
| 34 | int main(int argc, char* argv[]) | 42 | int main(int argc, char* argv[]) |
| 35 | { | 43 | { |
| @@ -88,7 +96,7 @@ int main(int argc, char* argv[]) | |||
| 88 | } | 96 | } |
| 89 | 97 | ||
| 90 | #if DEBUG | 98 | #if DEBUG |
| 91 | memory.dump(cout); | 99 | memory.dump(cerr); |
| 92 | #endif | 100 | #endif |
| 93 | } | 101 | } |
| 94 | 102 | ||
| @@ -116,7 +124,7 @@ int main(int argc, char* argv[]) | |||
| 116 | } | 124 | } |
| 117 | 125 | ||
| 118 | #if DEBUG | 126 | #if DEBUG |
| 119 | program.dump(cout); | 127 | program.dump(cerr); |
| 120 | #endif | 128 | #endif |
| 121 | 129 | ||
| 122 | 130 | ||
| @@ -128,7 +136,7 @@ int main(int argc, char* argv[]) | |||
| 128 | cpu.setProgram(&program); | 136 | cpu.setProgram(&program); |
| 129 | cpu.run(); | 137 | cpu.run(); |
| 130 | #if DEBUG | 138 | #if DEBUG |
| 131 | //cpu.dumpRegisters(cout); | 139 | //cpu.dumpRegisters(cerr); |
| 132 | #endif | 140 | #endif |
| 133 | } | 141 | } |
| 134 | catch(runtime_error& ex) | 142 | catch(runtime_error& ex) |
| @@ -136,8 +144,7 @@ int main(int argc, char* argv[]) | |||
| 136 | cerr << me << ": Error while executing program:" << endl | 144 | cerr << me << ": Error while executing program:" << endl |
| 137 | << " " << ex.what() << endl; | 145 | << " " << ex.what() << endl; |
| 138 | #if DEBUG | 146 | #if DEBUG |
| 139 | memory.dump(cout); | 147 | memory.dump(cerr); |
| 140 | //cpu.dumpRegisters(cout); | ||
| 141 | #endif | 148 | #endif |
| 142 | return 1; | 149 | return 1; |
| 143 | } | 150 | } |
diff --git a/ue3/mycpu/test/test.sh b/ue3/mycpu/test/test.sh new file mode 100755 index 0000000..ad2ae4d --- /dev/null +++ b/ue3/mycpu/test/test.sh | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | binary="./mycpu" | ||
| 4 | tmpfile="test/tmpfile" | ||
| 5 | inputs=( $(ls test/* | grep _program | sort -n) ) | ||
| 6 | |||
| 7 | for input in ${inputs[@]} | ||
| 8 | do | ||
| 9 | echo "Testing $input ..." | ||
| 10 | |||
| 11 | programfile="$input" | ||
| 12 | args="-c $programfile" | ||
| 13 | memoryfile="${input/_program/_memory}" | ||
| 14 | reffile="${input/_program/_output}" | ||
| 15 | if [ -e "$memoryfile" ] | ||
| 16 | then | ||
| 17 | args+=" -m $memoryfile" | ||
| 18 | fi | ||
| 19 | |||
| 20 | if [ ! -e "$reffile" ] | ||
| 21 | then | ||
| 22 | echo " ERROR: reference file $reffile doesn't exist" | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | rm -rf "$tmpfile" | ||
| 27 | echo " Executing $binary $args ..." | ||
| 28 | $binary $args > $tmpfile | ||
| 29 | |||
| 30 | md5_1=$(md5sum < "$reffile") | ||
| 31 | md5_2=$(md5sum < "$tmpfile") | ||
| 32 | if [ "$md5_1" != "$md5_2" ] | ||
| 33 | then | ||
| 34 | echo " ERROR: output and $reffile differ" | ||
| 35 | diff -Nau $reffile $tmpfile | ||
| 36 | exit 1 | ||
| 37 | else | ||
| 38 | echo " SUCCESS" | ||
| 39 | fi | ||
| 40 | done | ||
diff --git a/ue3/mycpu/test/test1_memory b/ue3/mycpu/test/test1_memory new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/ue3/mycpu/test/test1_memory | |||
| @@ -0,0 +1 @@ | |||
| 20 | |||
diff --git a/ue3/mycpu/test/test1_output b/ue3/mycpu/test/test1_output new file mode 100644 index 0000000..ac30dc2 --- /dev/null +++ b/ue3/mycpu/test/test1_output | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
diff --git a/ue3/mycpu/test/test1_program b/ue3/mycpu/test/test1_program new file mode 100644 index 0000000..ae5e9d2 --- /dev/null +++ b/ue3/mycpu/test/test1_program | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # set R2 = 10 | ||
| 2 | LOAD R2, R1 | ||
| 3 | |||
| 4 | # start of loop | ||
| 5 | label Loop: | ||
| 6 | inc R3 | ||
| 7 | sub R4, R3, R2 | ||
| 8 | test R4 | ||
| 9 | jumpz EndLoop | ||
| 10 | write WDEZ, R3 | ||
| 11 | jumpa Loop | ||
| 12 | |||
| 13 | label EndLoop: | ||
