diff options
| author | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 19:53:07 +0200 |
|---|---|---|
| committer | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 19:53:07 +0200 |
| commit | e41c92320aef4a54b7f3b323f7302b180019b6d7 (patch) | |
| tree | da2fba968ad9e2a997b8497c32929c885eb95558 /ue3/mycpu/cinstruction.cpp | |
| parent | 34483e07a0548d32651cda4ca4282f3cf8cae870 (diff) | |
| download | ooprog-e41c92320aef4a54b7f3b323f7302b180019b6d7.tar.gz ooprog-e41c92320aef4a54b7f3b323f7302b180019b6d7.tar.bz2 ooprog-e41c92320aef4a54b7f3b323f7302b180019b6d7.zip | |
some changes
Diffstat (limited to 'ue3/mycpu/cinstruction.cpp')
| -rw-r--r-- | ue3/mycpu/cinstruction.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp index 2c8dedf..3cbb033 100644 --- a/ue3/mycpu/cinstruction.cpp +++ b/ue3/mycpu/cinstruction.cpp | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include <iostream> | 1 | #include <iostream> |
| 2 | #include <sstream> | ||
| 2 | #include <vector> | 3 | #include <vector> |
| 3 | #include <map> | 4 | #include <map> |
| 4 | #include "cinstruction.h" | 5 | #include "cinstruction.h" |
| @@ -28,6 +29,7 @@ void CSub::exec(CMem& mem, vector<string>& instr) | |||
| 28 | { | 29 | { |
| 29 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) - | 30 | mem.getRegister(instr[1]) = mem.getRegister(instr[2]) - |
| 30 | mem.getRegister(instr[3]); | 31 | mem.getRegister(instr[3]); |
| 32 | |||
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | 35 | ||
| @@ -47,7 +49,9 @@ void CDiv::exec(CMem& mem, vector<string>& instr) | |||
| 47 | 49 | ||
| 48 | void CLoad::exec(CMem& mem, vector<string>& instr) | 50 | void CLoad::exec(CMem& mem, vector<string>& instr) |
| 49 | { | 51 | { |
| 50 | mem.getRegister(instr[1]) = mem.getMem(instr[2]); | 52 | istringstream stmp ("22"); |
| 53 | stmp >> mem.getRegister(instr[1]); | ||
| 54 | cout <<mem.getRegister(instr[1])<<" "<< mem.getMem(instr[2])<<endl; | ||
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | 57 | ||
| @@ -57,17 +61,18 @@ void CStore::exec(CMem& mem, vector<string>& instr) | |||
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | 63 | ||
| 60 | void CTest::test(CMem& mem, vector<string>& instr, bool& f_zero, bool& f_sign) | 64 | void CTest::exec(CMem& mem, vector<string>& instr) |
| 61 | { | 65 | { |
| 62 | if(mem.getRegister(instr[1]) == 0) | 66 | if(mem.getRegister(instr[1]) == 0) |
| 63 | f_zero = true; | 67 | f_zero = true; |
| 64 | else | 68 | else |
| 65 | f_zero = false; | 69 | f_zero = false; |
| 66 | 70 | ||
| 67 | if(mem.getRegister(instr[1]) <= 0) | 71 | if(mem.getRegister(instr[1]) < 0) |
| 68 | f_sign = true; | 72 | f_sign = true; |
| 69 | else | 73 | else |
| 70 | f_sign = false; | 74 | f_sign = false; |
| 75 | |||
| 71 | } | 76 | } |
| 72 | 77 | ||
| 73 | 78 | ||
| @@ -76,26 +81,27 @@ void CTest::test(CMem& mem, vector<string>& instr, bool& f_zero, bool& f_sign) | |||
| 76 | 81 | ||
| 77 | void CJumpa::exec(CMem& mem, vector<string>& instr) | 82 | void CJumpa::exec(CMem& mem, vector<string>& instr) |
| 78 | { | 83 | { |
| 79 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | 84 | mem.getRegister("R0") = (int) m_jumpaddr[instr[1]]; |
| 80 | } | 85 | } |
| 81 | 86 | ||
| 82 | 87 | ||
| 83 | void CJumpz::exec(CMem& mem, vector<string>& instr, bool& f_zero) | 88 | void CJumpz::exec(CMem& mem, vector<string>& instr) |
| 84 | { | 89 | { |
| 85 | if(f_zero) | 90 | if(f_zero) |
| 86 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | 91 | mem.getRegister("R0") = (int) m_jumpaddr[instr[1]]; |
| 87 | } | 92 | } |
| 88 | 93 | ||
| 89 | 94 | ||
| 90 | void CJumps::exec(CMem& mem, vector<string>& instr, bool& f_sign) | 95 | void CJumps::exec(CMem& mem, vector<string>& instr) |
| 91 | { | 96 | { |
| 92 | if(f_sign) | 97 | if(f_sign) |
| 93 | mem.getRegister(instr[0]) = (int) m_jumpaddr[instr[1]]; | 98 | mem.getRegister("R0") = (int) m_jumpaddr[instr[1]]; |
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | 101 | ||
| 97 | void CWrite::exec(CMem& mem, vector<string>& instr) | 102 | void CWrite::exec(CMem& mem, vector<string>& instr) |
| 98 | { | 103 | { |
| 104 | |||
| 99 | if(instr[1] == "WDEZ") | 105 | if(instr[1] == "WDEZ") |
| 100 | cout << mem.getRegister(instr[2]) << endl; | 106 | cout << mem.getRegister(instr[2]) << endl; |
| 101 | else if (instr[1] == "WHEX") | 107 | else if (instr[1] == "WHEX") |
