From 7adbb05bcd21cb9fe830827693ae6c69a8b08d2a Mon Sep 17 00:00:00 2001 From: Martin Perner Date: Wed, 3 Nov 2010 15:17:18 +0100 Subject: [PATCH] sim: stw added --- 3c_disasm/instr/stw.cpp | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 3c_disasm/instr/stw.cpp diff --git a/3c_disasm/instr/stw.cpp b/3c_disasm/instr/stw.cpp new file mode 100644 index 0000000..aec062b --- /dev/null +++ b/3c_disasm/instr/stw.cpp @@ -0,0 +1,77 @@ +#include "../Iinstr.hpp" + + +class Cstw : public Iinstr { + public: + Cstw(); + void evalInstr(); + void execInstr(); + std::string toString(); + Iinstr* getNew(); +}; + +/** + * Name: create_instruction + * Purpose: if compiled as shared library, this functions creates the + instruction object + + * Returns: pointer to instruction object + */ +extern "C" Iinstr* create_instruction() { + return new Cstw(); +} + +Iinstr* Cstw::getNew() +{ + return new Cstw(); +} + +/** + * Name: destroy_instruction + * Purpose: if compiled as shared library, this functions destoys the + instruction object + + * Parameter: IInstruction - the instruction object to delete + */ +extern "C" void destroy_instruction(Iinstr* p) { + delete p; +} + +Cstw::Cstw() +{ + opcode = B5(01111); + name = "stw"; +} + +void Cstw::evalInstr() +{ + this->m_s = true; + + dynamic_bitset<> immb = argbits; + immb.resize(15); + this->m_imm = this->generate15ImmSign(immb.to_ulong()); + + argbits >>= 15; + m_ra = this->getRegister(argbits); + argbits >>= 4; + m_rd = this->getRegister(argbits); + +} + +void Cstw::execInstr() +{ + //cout << "should exec " << this->toString() << endl; + CDat val = this->m_cpu->getRegister(this->m_ra); + val += m_imm; + this->m_cpu->setRAM(val, this->m_cpu->getRegister(this->m_rd)); +} + +std::string Cstw::toString() +{ + stringstream op; + op << this->getName(); + + op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")"; + + return op.str(); +} -- 2.25.1