summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/ccpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ue3/mycpu/ccpu.cpp')
-rw-r--r--ue3/mycpu/ccpu.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/ue3/mycpu/ccpu.cpp b/ue3/mycpu/ccpu.cpp
new file mode 100644
index 0000000..72ad96c
--- /dev/null
+++ b/ue3/mycpu/ccpu.cpp
@@ -0,0 +1,97 @@
1/**
2 * @module ccpu
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief class for processing a program
5 * @date 11.05.2009
6 */
7
8#include <fstream>
9#include <boost/tokenizer.hpp>
10#include <boost/algorithm/string.hpp>
11
12#include "ccpu.h"
13#include "cinstruction.h"
14#include "cprogram.h"
15#include "cmem.h"
16
17
18using namespace std;
19using namespace boost;
20
21CCPU::CCPU(const std::string& progfile, const std::string& memfile)
22 : m_program(progfile), m_memory(memfile)
23{
24 m_instrtype["inc"] = new CInc();
25 m_instrtype["dec"] = new CDec();
26 m_instrtype["add"] = new CAdd();
27 m_instrtype["sub"] = new CSub();
28 m_instrtype["mul"] = new CMul();
29 m_instrtype["div"] = new CDiv();
30 m_instrtype["load"] = new CLoad();
31 m_instrtype["store"] = new CStore();
32 m_instrtype["test"] = new CTest();
33 m_instrtype["label"] = new CLabel();
34 m_instrtype["jumpa"] = new CJumpa(m_program.getJumpAddrs());
35 m_instrtype["jumpz"] = new CJumpz(m_program.getJumpAddrs());
36 m_instrtype["jumps"] = new CJumps(m_program.getJumpAddrs());
37 m_instrtype["write"] = new CWrite();
38}
39
40
41void CCPU::proceed()
42{
43
44 while (m_memory.getRegister("R0") < m_program.getMaxProgramCount())
45 {
46 std::vector<std::string>& i_list = m_program.getInstruction(
47 m_memory.getRegister("R0")
48 );
49
50 /* switch (m_instrtype[i_list[0]])
51 {
52 case INC:
53 cout << "fick mich"<< endl<<endl;
54 break;
55 case DEC:
56 break;
57 case ADD:
58 break;
59 case SUB:
60 cout << "sub"<< endl<<endl;
61 break;
62 case MUL:
63 break;
64 case DIV:
65 break;
66 case LOAD:
67 cout << "load"<< endl<<endl;
68 break;
69 case STORE:
70 break;
71 case TEST:
72 break;
73 case LABEL:
74 break;
75 case JUMPA:
76 break;
77 case JUMPZ:
78 break;
79 case JUMPS:
80 break;
81 default:
82 break;
83 } */
84
85 for(int i = 0; i < (int)i_list.size(); i++)
86 cout << i_list[i] << " ";
87 m_memory.getRegister("R0")++;
88 cout << m_memory.getRegister("R0")<< endl<<endl;
89 }
90}
91
92void CCPU::execInstruction(CInstruction& instr, vector<string>& i_list)
93{
94
95
96}
97