summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/cinstruction.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-12 23:18:17 +0200
committermanuel <manuel@nc8430.lan>2009-05-12 23:18:17 +0200
commit45581d3d376e8deed84952cb838ae330549e5241 (patch)
treeab23bd5cc1f2e32e95faa372b3b46e69ccb6a3c3 /ue3/mycpu/cinstruction.cpp
parentfe1ef6b47f59899e8687bb1dcc92eba1d103a08f (diff)
downloadooprog-45581d3d376e8deed84952cb838ae330549e5241.tar.gz
ooprog-45581d3d376e8deed84952cb838ae330549e5241.tar.bz2
ooprog-45581d3d376e8deed84952cb838ae330549e5241.zip
my cpu design
Diffstat (limited to 'ue3/mycpu/cinstruction.cpp')
-rw-r--r--ue3/mycpu/cinstruction.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp
new file mode 100644
index 0000000..32bdd2f
--- /dev/null
+++ b/ue3/mycpu/cinstruction.cpp
@@ -0,0 +1,46 @@
1/**
2 * @module cinstruction
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief TODO
5 * @date 10.05.2009
6 */
7
8#include <sstream>
9#include <stdexcept>
10#include <boost/lexical_cast.hpp>
11#include "cinstruction.h"
12#include "ccpu.h"
13
14using namespace std;
15
16const unsigned CInstruction::parseRegister(const std::string& str)
17{
18 unsigned reg;
19 if (str.length() < 2 || str[0] != 'R')
20 throw runtime_error("Invalid syntax of register");
21
22 try
23 {
24 reg = boost::lexical_cast<unsigned>(str.substr(1));
25 }
26 catch(boost::bad_lexical_cast& ex)
27 {
28 throw runtime_error("Invalid syntax of register");
29 }
30
31 return reg;
32}
33
34/*----------------------------------------------------------------------------*/
35
36inline void CInstruction::checkRegister(CCPU *cpu, unsigned regidx)
37{
38 if (regidx >= cpu->getRegisterCount())
39 {
40 stringstream sstr;
41 sstr << "Register R" << regidx << " doesn't exist (out of bound)";
42 throw runtime_error(sstr.str());
43 }
44}
45
46/* vim: set et sw=2 ts=2: */