From ddf63e2765a6b225d18c59321595e69e1a126e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Neuwirth?= Date: Tue, 12 May 2009 23:00:03 +0200 Subject: adding tha rest --- ue3/mycpu/cinstruction.cpp | 8 ++--- ue3/mycpu/cmem.cpp | 70 ++++++++++++++++++++++++++++++++++++++++---- ue3/mycpu/cmem.h | 19 +++++------- ue3/mycpu/test/test_prog | 2 ++ ue3/mycpu/test/test_prog_mem | 7 ++++- 5 files changed, 84 insertions(+), 22 deletions(-) diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp index 3cbb033..12c5c74 100644 --- a/ue3/mycpu/cinstruction.cpp +++ b/ue3/mycpu/cinstruction.cpp @@ -49,15 +49,15 @@ void CDiv::exec(CMem& mem, vector& instr) void CLoad::exec(CMem& mem, vector& instr) { - istringstream stmp ("22"); - stmp >> mem.getRegister(instr[1]); - cout <> mem.getRegister(instr[1]); + } void CStore::exec(CMem& mem, vector& instr) { - mem.setMem(instr[2], mem.getRegister(instr[1])); + mem.setMemAt(instr[2], mem.getRegister(instr[1])); } diff --git a/ue3/mycpu/cmem.cpp b/ue3/mycpu/cmem.cpp index ec60b56..165747b 100644 --- a/ue3/mycpu/cmem.cpp +++ b/ue3/mycpu/cmem.cpp @@ -37,13 +37,9 @@ CMem::~CMem() CDat& CMem::getRegister(const string reg) { - istringstream stmp ( - reg.substr(reg.find_first_of("R") + 1, reg.size()) - ); - unsigned int regnr; - stmp >> regnr; - + unsigned int regnr = getRegNr(reg); + // if (regnr >= MAX_REGISTER ) if (regnr >= m_registers.size()) @@ -55,6 +51,68 @@ CDat& CMem::getRegister(const string reg) return m_registers[regnr]; } + +/*----------------------------------------------------------------------------*/ + +string CMem::getMemAt(const std::string addr) +{ + int pos = getRegister(addr).getTypeValue(); + /* open and read mem */ + ifstream file(m_memfile.c_str(), ios::in); + string cur_line; + for (int i = 0; i <= pos; i++) + getline(file, cur_line); + + file.close(); + if (cur_line.empty()) + return ""; + trim(cur_line); + return cur_line; +} +void CMem::setMemAt(const std::string addr, const CDat& value) +{ + unsigned int pos = getRegister(addr).getTypeValue(); + /* open and read mem */ + ifstream ifile(m_memfile.c_str() ); + vector tmp; + unsigned int i = 0; + while (ifile.good()) + { + string cur_line; + getline(ifile, cur_line); + if(!cur_line.empty()) + tmp.push_back(cur_line); + i++; + } + ifile.close(); + cout << tmp.size()<<"sasa"<> regnr; + return regnr; +} + /*----------------------------------------------------------------------------*/ #ifdef DEBUG diff --git a/ue3/mycpu/cmem.h b/ue3/mycpu/cmem.h index 06fa876..356c9c0 100644 --- a/ue3/mycpu/cmem.h +++ b/ue3/mycpu/cmem.h @@ -60,13 +60,9 @@ class CMem CDat& getRegister(const std::string reg); - CDat& getMem(const std::string addr) - { - getRegister("R255") = 10; - return getRegister("R255"); - } - void setMem(const std::string addr, const CDat& value) - {} + std::string getMemAt(const std::string addr); + + void setMemAt(const std::string addr, const CDat& value); #ifdef DEBUG /** @@ -83,11 +79,12 @@ class CMem private: - /* members */ - std::string m_memfile; - - std::vector m_registers; + unsigned int getRegNr(const std::string reg); + + /* members */ + std::string m_memfile; + std::vector m_registers; }; #endif diff --git a/ue3/mycpu/test/test_prog b/ue3/mycpu/test/test_prog index 74dac21..b50575b 100644 --- a/ue3/mycpu/test/test_prog +++ b/ue3/mycpu/test/test_prog @@ -1,4 +1,5 @@ # set R2 = 10 + load R2, R1 # start of loop @@ -8,6 +9,7 @@ sub R4, R3, R2 test R4 jumpz EndLoop write WDEZ, R3 +store R3, R1 jumpa Loop label EndLoop: diff --git a/ue3/mycpu/test/test_prog_mem b/ue3/mycpu/test/test_prog_mem index f599e28..8c3e80f 100644 --- a/ue3/mycpu/test/test_prog_mem +++ b/ue3/mycpu/test/test_prog_mem @@ -1 +1,6 @@ -10 +9 +3 +4 +5 +4 +3 -- cgit v1.2.3