diff options
Diffstat (limited to 'ue4/mycpu/instructions.h')
| -rw-r--r-- | ue4/mycpu/instructions.h | 454 |
1 files changed, 454 insertions, 0 deletions
diff --git a/ue4/mycpu/instructions.h b/ue4/mycpu/instructions.h new file mode 100644 index 0000000..4c36562 --- /dev/null +++ b/ue4/mycpu/instructions.h | |||
| @@ -0,0 +1,454 @@ | |||
| 1 | /** | ||
| 2 | * @module instructions | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Implementations of CInstruction | ||
| 5 | * @date 10.05.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef INSTRUCTIONS_H | ||
| 9 | #define INSTRUCTIONS_H 1 | ||
| 10 | |||
| 11 | #include "cinstruction.h" | ||
| 12 | #include "ccpu.h" | ||
| 13 | |||
| 14 | /** | ||
| 15 | * @class CInstructionInc | ||
| 16 | * | ||
| 17 | * Implementation of assembler command "inc" | ||
| 18 | * Syntax: inc R1 | ||
| 19 | * (R1++) | ||
| 20 | */ | ||
| 21 | class CInstructionInc | ||
| 22 | : public CInstruction | ||
| 23 | { | ||
| 24 | public: | ||
| 25 | CInstructionInc() | ||
| 26 | : CInstruction("inc") | ||
| 27 | {} | ||
| 28 | |||
| 29 | CInstructionInc *factory() | ||
| 30 | { | ||
| 31 | return new CInstructionInc; | ||
| 32 | } | ||
| 33 | |||
| 34 | void compile(std::list<std::string>& params); | ||
| 35 | void execute(CCPU *cpu); | ||
| 36 | |||
| 37 | protected: | ||
| 38 | /** register number */ | ||
| 39 | unsigned m_regidx1; | ||
| 40 | }; | ||
| 41 | |||
| 42 | /*============================================================================*/ | ||
| 43 | |||
| 44 | /** | ||
| 45 | * @class CInstructionDec | ||
| 46 | * | ||
| 47 | * Implementation of assembler command "dec" | ||
| 48 | * Syntax: dec R1 | ||
| 49 | * (R1--) | ||
| 50 | */ | ||
| 51 | class CInstructionDec | ||
| 52 | : public CInstruction | ||
| 53 | { | ||
| 54 | public: | ||
| 55 | CInstructionDec() | ||
| 56 | : CInstruction("dec") | ||
| 57 | {} | ||
| 58 | |||
| 59 | CInstructionDec *factory() | ||
| 60 | { | ||
| 61 | return new CInstructionDec; | ||
| 62 | } | ||
| 63 | |||
| 64 | void compile(std::list<std::string>& params); | ||
| 65 | void execute(CCPU *cpu); | ||
| 66 | |||
| 67 | protected: | ||
| 68 | /** register number */ | ||
| 69 | unsigned m_regidx1; | ||
| 70 | }; | ||
| 71 | |||
| 72 | /*============================================================================*/ | ||
| 73 | |||
| 74 | /** | ||
| 75 | * @class CInstructionAdd | ||
| 76 | * | ||
| 77 | * Implementation of assembler command "add" | ||
| 78 | * Syntax: add R1, R2, R3 | ||
| 79 | * (R1 = R2 + R3) | ||
| 80 | */ | ||
| 81 | class CInstructionAdd | ||
| 82 | : public CInstruction | ||
| 83 | { | ||
| 84 | public: | ||
| 85 | CInstructionAdd() | ||
| 86 | : CInstruction("add") | ||
| 87 | {} | ||
| 88 | |||
| 89 | CInstructionAdd *factory() | ||
| 90 | { | ||
| 91 | return new CInstructionAdd; | ||
| 92 | } | ||
| 93 | |||
| 94 | void compile(std::list<std::string>& params); | ||
| 95 | void execute(CCPU *cpu); | ||
| 96 | |||
| 97 | protected: | ||
| 98 | /** register number */ | ||
| 99 | unsigned m_regidx1; | ||
| 100 | /** register number */ | ||
| 101 | unsigned m_regidx2; | ||
| 102 | /** register number */ | ||
| 103 | unsigned m_regidx3; | ||
| 104 | }; | ||
| 105 | |||
| 106 | /*============================================================================*/ | ||
| 107 | |||
| 108 | /** | ||
| 109 | * @class CInstructionSub | ||
| 110 | * | ||
| 111 | * Implementation of assembler command "sub" | ||
| 112 | * Syntax: sub R1, R2, R3 | ||
| 113 | * (R1 = R2 - R3) | ||
| 114 | */ | ||
| 115 | class CInstructionSub | ||
| 116 | : public CInstruction | ||
| 117 | { | ||
| 118 | public: | ||
| 119 | CInstructionSub() | ||
| 120 | : CInstruction("sub") | ||
| 121 | {} | ||
| 122 | |||
| 123 | CInstructionSub *factory() | ||
| 124 | { | ||
| 125 | return new CInstructionSub; | ||
| 126 | } | ||
| 127 | |||
| 128 | void compile(std::list<std::string>& params); | ||
| 129 | void execute(CCPU *cpu); | ||
| 130 | |||
| 131 | protected: | ||
| 132 | /** register number */ | ||
| 133 | unsigned m_regidx1; | ||
| 134 | /** register number */ | ||
| 135 | unsigned m_regidx2; | ||
| 136 | /** register number */ | ||
| 137 | unsigned m_regidx3; | ||
| 138 | }; | ||
| 139 | |||
| 140 | /*============================================================================*/ | ||
| 141 | |||
| 142 | /** | ||
| 143 | * @class CInstructionMul | ||
| 144 | * | ||
| 145 | * Implementation of assembler command "mul" | ||
| 146 | * Syntax: mul R1, R2, R3 | ||
| 147 | * (R1 = R2 * R3) | ||
| 148 | */ | ||
| 149 | class CInstructionMul | ||
| 150 | : public CInstruction | ||
| 151 | { | ||
| 152 | public: | ||
| 153 | CInstructionMul() | ||
| 154 | : CInstruction("mul") | ||
| 155 | {} | ||
| 156 | |||
| 157 | CInstructionMul *factory() | ||
| 158 | { | ||
| 159 | return new CInstructionMul; | ||
| 160 | } | ||
| 161 | |||
| 162 | void compile(std::list<std::string>& params); | ||
| 163 | void execute(CCPU *cpu); | ||
| 164 | |||
| 165 | protected: | ||
| 166 | /** register number */ | ||
| 167 | unsigned m_regidx1; | ||
| 168 | /** register number */ | ||
| 169 | unsigned m_regidx2; | ||
| 170 | /** register number */ | ||
| 171 | unsigned m_regidx3; | ||
| 172 | }; | ||
| 173 | |||
| 174 | /*============================================================================*/ | ||
| 175 | |||
| 176 | /** | ||
| 177 | * @class CInstructionDiv | ||
| 178 | * | ||
| 179 | * Implementation of assembler command "div" | ||
| 180 | * Syntax: div R1, R2, R3 | ||
| 181 | * (R1 = R2 / R3) | ||
| 182 | */ | ||
| 183 | class CInstructionDiv | ||
| 184 | : public CInstruction | ||
| 185 | { | ||
| 186 | public: | ||
| 187 | CInstructionDiv() | ||
| 188 | : CInstruction("div") | ||
| 189 | {} | ||
| 190 | |||
| 191 | CInstructionDiv *factory() | ||
| 192 | { | ||
| 193 | return new CInstructionDiv; | ||
| 194 | } | ||
| 195 | |||
| 196 | void compile(std::list<std::string>& params); | ||
| 197 | void execute(CCPU *cpu); | ||
| 198 | |||
| 199 | protected: | ||
| 200 | /** register number */ | ||
| 201 | unsigned m_regidx1; | ||
| 202 | /** register number */ | ||
| 203 | unsigned m_regidx2; | ||
| 204 | /** register number */ | ||
| 205 | unsigned m_regidx3; | ||
| 206 | }; | ||
| 207 | |||
| 208 | /*============================================================================*/ | ||
| 209 | |||
| 210 | /** | ||
| 211 | * @class CInstructionLoad | ||
| 212 | * | ||
| 213 | * Implementation of assembler command "load" | ||
| 214 | * Syntax: load R1, R2 | ||
| 215 | * (R1 = memory[R2]) | ||
| 216 | */ | ||
| 217 | class CInstructionLoad | ||
| 218 | : public CInstruction | ||
| 219 | { | ||
| 220 | public: | ||
| 221 | CInstructionLoad() | ||
| 222 | : CInstruction("load") | ||
| 223 | {} | ||
| 224 | |||
| 225 | CInstructionLoad *factory() | ||
| 226 | { | ||
| 227 | return new CInstructionLoad; | ||
| 228 | } | ||
| 229 | |||
| 230 | void compile(std::list<std::string>& params); | ||
| 231 | void execute(CCPU *cpu); | ||
| 232 | |||
| 233 | protected: | ||
| 234 | /** register number */ | ||
| 235 | unsigned m_regidx1; | ||
| 236 | /** register number */ | ||
| 237 | unsigned m_regidx2; | ||
| 238 | }; | ||
| 239 | |||
| 240 | /*============================================================================*/ | ||
| 241 | |||
| 242 | /** | ||
| 243 | * @class CInstructionStore | ||
| 244 | * | ||
| 245 | * Implementation of assembler command "store" | ||
| 246 | * Syntax: store R1, R2 | ||
| 247 | * (memory[R2] = R1) | ||
| 248 | */ | ||
| 249 | class CInstructionStore | ||
| 250 | : public CInstruction | ||
| 251 | { | ||
| 252 | public: | ||
| 253 | CInstructionStore() | ||
| 254 | : CInstruction("store") | ||
| 255 | {} | ||
| 256 | |||
| 257 | CInstructionStore *factory() | ||
| 258 | { | ||
| 259 | return new CInstructionStore; | ||
| 260 | } | ||
| 261 | |||
| 262 | void compile(std::list<std::string>& params); | ||
| 263 | void execute(CCPU *cpu); | ||
| 264 | |||
| 265 | protected: | ||
| 266 | /** register number */ | ||
| 267 | unsigned m_regidx1; | ||
| 268 | /** register number */ | ||
| 269 | unsigned m_regidx2; | ||
| 270 | }; | ||
| 271 | |||
| 272 | /*============================================================================*/ | ||
| 273 | |||
| 274 | /** | ||
| 275 | * @class CInstructionTest | ||
| 276 | * | ||
| 277 | * Implementation of assembler command "test" | ||
| 278 | * Syntax: test R1 | ||
| 279 | * (R1 == 0: zeroflag: true, R1 < 0: signflag: true) | ||
| 280 | */ | ||
| 281 | class CInstructionTest | ||
| 282 | : public CInstruction | ||
| 283 | { | ||
| 284 | public: | ||
| 285 | CInstructionTest() | ||
| 286 | : CInstruction("test") | ||
| 287 | {} | ||
| 288 | |||
| 289 | CInstructionTest *factory() | ||
| 290 | { | ||
| 291 | return new CInstructionTest; | ||
| 292 | } | ||
| 293 | |||
| 294 | void compile(std::list<std::string>& params); | ||
| 295 | void execute(CCPU *cpu); | ||
| 296 | |||
| 297 | protected: | ||
| 298 | /** register number */ | ||
| 299 | unsigned m_regidx1; | ||
| 300 | }; | ||
| 301 | |||
| 302 | /*============================================================================*/ | ||
| 303 | |||
| 304 | /** | ||
| 305 | * @class CInstructionLabel | ||
| 306 | * | ||
| 307 | * Implementation of assembler command "label" | ||
| 308 | * Syntax: label name: | ||
| 309 | */ | ||
| 310 | class CInstructionLabel | ||
| 311 | : public CInstruction | ||
| 312 | { | ||
| 313 | public: | ||
| 314 | CInstructionLabel() | ||
| 315 | : CInstruction("label") | ||
| 316 | {} | ||
| 317 | |||
| 318 | CInstructionLabel *factory() | ||
| 319 | { | ||
| 320 | return new CInstructionLabel; | ||
| 321 | } | ||
| 322 | |||
| 323 | void compile(std::list<std::string>& params) | ||
| 324 | {} | ||
| 325 | |||
| 326 | void execute(CCPU *cpu) | ||
| 327 | {} | ||
| 328 | }; | ||
| 329 | |||
| 330 | /*============================================================================*/ | ||
| 331 | |||
| 332 | /** | ||
| 333 | * @class CInstructionJumpA | ||
| 334 | * | ||
| 335 | * Implementation of assembler command "jumpa" | ||
| 336 | * Syntax: jumpa labelname | ||
| 337 | * (jump to labelname) | ||
| 338 | */ | ||
| 339 | class CInstructionJumpA | ||
| 340 | : public CInstruction | ||
| 341 | { | ||
| 342 | public: | ||
| 343 | CInstructionJumpA() | ||
| 344 | : CInstruction("jumpa"), m_addr("") | ||
| 345 | {} | ||
| 346 | |||
| 347 | CInstructionJumpA *factory() | ||
| 348 | { | ||
| 349 | return new CInstructionJumpA; | ||
| 350 | } | ||
| 351 | |||
| 352 | void compile(std::list<std::string>& params); | ||
| 353 | void execute(CCPU *cpu); | ||
| 354 | |||
| 355 | protected: | ||
| 356 | /** labelname */ | ||
| 357 | std::string m_addr; | ||
| 358 | }; | ||
| 359 | |||
| 360 | /*============================================================================*/ | ||
| 361 | |||
| 362 | /** | ||
| 363 | * @class CInstructionJumpZ | ||
| 364 | * | ||
| 365 | * Implementation of assembler command "jumpz" | ||
| 366 | * Syntax: jumpz labelname | ||
| 367 | * (jump to labelname if zeroflag) | ||
| 368 | */ | ||
| 369 | class CInstructionJumpZ | ||
| 370 | : public CInstruction | ||
| 371 | { | ||
| 372 | public: | ||
| 373 | CInstructionJumpZ() | ||
| 374 | : CInstruction("jumpz"), m_addr("") | ||
| 375 | {} | ||
| 376 | |||
| 377 | CInstructionJumpZ *factory() | ||
| 378 | { | ||
| 379 | return new CInstructionJumpZ; | ||
| 380 | } | ||
| 381 | |||
| 382 | void compile(std::list<std::string>& params); | ||
| 383 | void execute(CCPU *cpu); | ||
| 384 | |||
| 385 | protected: | ||
| 386 | /** labelname */ | ||
| 387 | std::string m_addr; | ||
| 388 | }; | ||
| 389 | |||
| 390 | /*============================================================================*/ | ||
| 391 | |||
| 392 | /** | ||
| 393 | * @class CInstructionJumpS | ||
| 394 | * | ||
| 395 | * Implementation of assembler command "jumps" | ||
| 396 | * Syntax: jumps labelname | ||
| 397 | * (jump to labelname if signflag) | ||
| 398 | */ | ||
| 399 | class CInstructionJumpS | ||
| 400 | : public CInstruction | ||
| 401 | { | ||
| 402 | public: | ||
| 403 | CInstructionJumpS() | ||
| 404 | : CInstruction("jumps"), m_addr("") | ||
| 405 | {} | ||
| 406 | |||
| 407 | CInstructionJumpS *factory() | ||
| 408 | { | ||
| 409 | return new CInstructionJumpS; | ||
| 410 | } | ||
| 411 | |||
| 412 | void compile(std::list<std::string>& params); | ||
| 413 | void execute(CCPU *cpu); | ||
| 414 | |||
| 415 | protected: | ||
| 416 | /** labelname */ | ||
| 417 | std::string m_addr; | ||
| 418 | }; | ||
| 419 | |||
| 420 | /*============================================================================*/ | ||
| 421 | |||
| 422 | /** | ||
| 423 | * @class CInstructionWrite | ||
| 424 | * | ||
| 425 | * Implementation of assembler command "write" | ||
| 426 | * Syntax: write DEV, R1 | ||
| 427 | * (write R1 to DEV, which is a name of a display) | ||
| 428 | */ | ||
| 429 | class CInstructionWrite | ||
| 430 | : public CInstruction | ||
| 431 | { | ||
| 432 | public: | ||
| 433 | CInstructionWrite() | ||
| 434 | : CInstruction("write"), m_dev("") | ||
| 435 | {} | ||
| 436 | |||
| 437 | CInstructionWrite *factory() | ||
| 438 | { | ||
| 439 | return new CInstructionWrite; | ||
| 440 | } | ||
| 441 | |||
| 442 | void compile(std::list<std::string>& params); | ||
| 443 | void execute(CCPU *cpu); | ||
| 444 | |||
| 445 | protected: | ||
| 446 | /** register number */ | ||
| 447 | unsigned m_regidx1; | ||
| 448 | /** device name */ | ||
| 449 | std::string m_dev; | ||
| 450 | }; | ||
| 451 | |||
| 452 | #endif | ||
| 453 | |||
| 454 | /* vim: set et sw=2 ts=2: */ | ||
