diff options
| author | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 15:27:58 +0200 |
|---|---|---|
| committer | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 15:27:58 +0200 |
| commit | 34483e07a0548d32651cda4ca4282f3cf8cae870 (patch) | |
| tree | ef499b9850e60cc45ca4de1605c962a5cc040a8f /ue3/mycpu/cinstruction.cpp | |
| parent | fe1ef6b47f59899e8687bb1dcc92eba1d103a08f (diff) | |
| download | ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.tar.gz ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.tar.bz2 ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.zip | |
adding rest of files
Diffstat (limited to 'ue3/mycpu/cinstruction.cpp')
| -rw-r--r-- | ue3/mycpu/cinstruction.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp new file mode 100644 index 0000000..2c8dedf --- /dev/null +++ b/ue3/mycpu/cinstruction.cpp | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <vector> | ||
| 3 | #include <map> | ||
| 4 | #include "cinstruction.h" | ||
| 5 | #include "cmem.h" | ||
| 6 | using namespace std; | ||
| 7 | |||
| 8 | void CInc::exec(CMem& mem, vector<string>& instr) | ||
| 9 | { | ||
| 10 | mem.getRegister(instr[1])++; | ||
| 11 | } | ||
| 12 | |||
| 13 | |||
| 14 | void CDec::exec(CMem& mem, vector<string>& instr) | ||
| 15 | { | ||
| 16 | mem.getRegister(instr[1])--; | ||
| 17 | } | ||
| 18 | |||
| 19 | |||
| 20 | void CAdd::exec(CMem& mem, vector<string>& instr) | ||
| 21 | { | ||
| 22 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) + | ||
| 23 | mem.getRegister(instr[3]); | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 | void CSub::exec(CMem& mem, vector<string>& instr) | ||
| 28 | { | ||
| 29 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) - | ||
| 30 | mem.getRegister(instr[3]); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | void CMul::exec(CMem& mem, vector<string>& instr) | ||
| 35 | { | ||
| 36 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) * | ||
| 37 | mem.getRegister(instr[3]); | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | void CDiv::exec(CMem& mem, vector<string>& instr) | ||
| 42 | { | ||
| 43 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) / | ||
| 44 | mem.getRegister(instr[3]); | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | void CLoad::exec(CMem& mem, vector<string>& instr) | ||
| 49 | { | ||
| 50 | mem.getRegister(instr[1]) = mem.getMem(instr[2]); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | void CStore::exec(CMem& mem, vector<string>& instr) | ||
| 55 | { | ||
| 56 | mem.setMem(instr[2], mem.getRegister(instr[1])); | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | void CTest::test(CMem& mem, vector<string>& instr, bool& f_zero, bool& f_sign) | ||
| 61 | { | ||
| 62 | if(mem.getRegister(instr[1]) == 0) | ||
| 63 | f_zero = true; | ||
| 64 | else | ||
| 65 | f_zero = false; | ||
| 66 | |||
| 67 | if(mem.getRegister(instr[1]) <= 0) | ||
| 68 | f_sign = true; | ||
| 69 | else | ||
| 70 | f_sign = false; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | void CJumpa::exec(CMem& mem, vector<string>& instr) | ||
| 78 | { | ||
| 79 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | void CJumpz::exec(CMem& mem, vector<string>& instr, bool& f_zero) | ||
| 84 | { | ||
| 85 | if(f_zero) | ||
| 86 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | void CJumps::exec(CMem& mem, vector<string>& instr, bool& f_sign) | ||
| 91 | { | ||
| 92 | if(f_sign) | ||
| 93 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | ||
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | void CWrite::exec(CMem& mem, vector<string>& instr) | ||
| 98 | { | ||
| 99 | if(instr[1] == "WDEZ") | ||
| 100 | cout << mem.getRegister(instr[2]) << endl; | ||
| 101 | else if (instr[1] == "WHEX") | ||
| 102 | cout << hex << mem.getRegister(instr[2]) << endl; | ||
| 103 | } | ||
| 104 | |||
