From 45581d3d376e8deed84952cb838ae330549e5241 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 May 2009 23:18:17 +0200 Subject: my cpu design --- ue3/mycpu/cinstruction.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ue3/mycpu/cinstruction.cpp (limited to 'ue3/mycpu/cinstruction.cpp') 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 @@ +/** + * @module cinstruction + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief TODO + * @date 10.05.2009 + */ + +#include +#include +#include +#include "cinstruction.h" +#include "ccpu.h" + +using namespace std; + +const unsigned CInstruction::parseRegister(const std::string& str) +{ + unsigned reg; + if (str.length() < 2 || str[0] != 'R') + throw runtime_error("Invalid syntax of register"); + + try + { + reg = boost::lexical_cast(str.substr(1)); + } + catch(boost::bad_lexical_cast& ex) + { + throw runtime_error("Invalid syntax of register"); + } + + return reg; +} + +/*----------------------------------------------------------------------------*/ + +inline void CInstruction::checkRegister(CCPU *cpu, unsigned regidx) +{ + if (regidx >= cpu->getRegisterCount()) + { + stringstream sstr; + sstr << "Register R" << regidx << " doesn't exist (out of bound)"; + throw runtime_error(sstr.str()); + } +} + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3