summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/ccpu.cpp
blob: 72ad96c82780fdb93010ee75ed41fc57ef257c94 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * @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)
{
	m_instrtype["inc"] = new CInc();
	m_instrtype["dec"] = new CDec();
	m_instrtype["add"] = new CAdd();
	m_instrtype["sub"] = new CSub();
	m_instrtype["mul"] = new CMul();
	m_instrtype["div"] = new CDiv();
	m_instrtype["load"] = new CLoad();
	m_instrtype["store"] = new CStore();
	m_instrtype["test"] = new CTest();
	m_instrtype["label"] = new CLabel();
	m_instrtype["jumpa"] = new CJumpa(m_program.getJumpAddrs());
	m_instrtype["jumpz"] = new CJumpz(m_program.getJumpAddrs());
	m_instrtype["jumps"] = new CJumps(m_program.getJumpAddrs());
	m_instrtype["write"] = new CWrite();
}


void CCPU::proceed()
{

	while (m_memory.getRegister("R0") < m_program.getMaxProgramCount())
	{
		 std::vector<std::string>& i_list = m_program.getInstruction(
		 																																	m_memory.getRegister("R0")
		 																																	);
		
	/*	switch (m_instrtype[i_list[0]])
		{
			case INC:
			cout << "fick mich"<< endl<<endl;	
				break;
			case DEC:
				break;
			case ADD:
				break;
			case SUB:
			cout << "sub"<< endl<<endl;	
					break;
			case MUL:
				break;
			case DIV:
				break;
			case LOAD:
				cout << "load"<< endl<<endl;	
					break;
			case STORE:
				break;
			case TEST:
				break;
			case LABEL:
				break;
			case JUMPA:
				break;
			case JUMPZ:
				break;
			case JUMPS:
				break;
			default:
				break;
		}				*/																
	
	for(int i = 0; i < (int)i_list.size(); i++)
		cout << i_list[i] << " ";
		m_memory.getRegister("R0")++;																													
		cout << m_memory.getRegister("R0")<< endl<<endl;	
	}
}

void CCPU::execInstruction(CInstruction& instr, vector<string>& i_list)
{
	

}