#include "../Iinstr.hpp" class Caddi : public Iinstr { public: Caddi(); 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 Caddi(); } Iinstr* Caddi::getNew() { return new Caddi(); } /** * 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; } Caddi::Caddi() { opcode = B5(00010); name = "addi"; } void Caddi::evalInstr() { this->m_s = argbits[2]; this->m_c = argbits[1]; this->m_d = argbits[0]; argbits >>= 3; dynamic_bitset<> immb = argbits; immb.resize(12); this->m_imm = this->generate12ImmSign(immb.to_ulong()); argbits >>= 12; m_ra = this->getRegister(argbits); argbits >>= 4; m_rd = this->getRegister(argbits); } void Caddi::execInstr() { //cout << "should exec " << this->toString() << endl; CDat ra = this->m_cpu->getRegister(m_ra); CDatd reg = ra + this->m_imm; this->m_cpu->setRegister(m_rd, reg); this->m_cpu->updateFlags(reg, ra, this->m_imm); } std::string Caddi::toString() { stringstream op; op << this->getName(); if(m_d) op << 'D'; if(m_s) op << 'S'; if(m_c) op << 'C'; op << this->getConditionFlag() << " r" << m_rd << ", r" << m_ra << ", " << m_imm; return op.str(); }