blob: 978f1f7f6485b15436ab10f782884bb2eaae4f18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/**
* @module ccpu
* @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
* @brief class for processing a program
* @date 11.05.2009
*/
#include <fstream>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include "ccpu.h"
#include "cinstruction.h"
#include "cprogram.h"
#include "cmem.h"
using namespace std;
using namespace boost;
CCPU::CCPU(const std::string& progfile, const std::string& memfile)
: m_program(progfile), m_memory(memfile)
{
f_zero = false;
f_sign = false;
m_instrHandler["inc"] = new CInc();
m_instrHandler["dec"] = new CDec();
m_instrHandler["add"] = new CAdd();
m_instrHandler["sub"] = new CSub();
m_instrHandler["mul"] = new CMul();
m_instrHandler["div"] = new CDiv();
m_instrHandler["load"] = new CLoad();
m_instrHandler["store"] = new CStore();
m_instrHandler["test"] = new CTest(f_zero, f_sign);
m_instrHandler["label"] = new CLabel();
m_instrHandler["jumpa"] = new CJumpa(m_program.getJumpAddrs());
m_instrHandler["jumpz"] = new CJumpz(f_zero, f_sign, m_program.getJumpAddrs());
m_instrHandler["jumps"] = new CJumps(f_zero, f_sign, m_program.getJumpAddrs());
m_instrHandler["write"] = new CWrite();
}
CCPU::~CCPU()
{
std::map<std::string, CInstruction *>::iterator it;
for (it = m_instrHandler.begin(); it != m_instrHandler.end(); it++)
delete (*it).second ;
}
void CCPU::proceed()
{
while (m_memory.getRegister("R0") < m_program.getMaxProgramCount())
{
std::vector<std::string>& i_list = m_program.getInstruction(
m_memory.getRegister("R0")
);
m_instrHandler[i_list[0]]->exec(m_memory, i_list);
/* for(int i = 0; i < (int)i_list.size(); i++)
cout << i_list[i] << " ";
if (i_list[0] == "load")
{
cout << m_memory.getRegister(i_list[1])<<" "<<m_memory.getRegister("R255")<<endl;
break;
}*/
m_memory.getRegister("R0")++;
// cout << m_memory.getRegister("R0")<<endl;
// cout<<endl;
}
}
|