#include "../Iinstr.hpp" class Csubi : public Iinstr { public: Csubi(); 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 Csubi(); } Iinstr* Csubi::getNew() { return new Csubi(); } /** * 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; } Csubi::Csubi() { opcode = B5(00011); name = "subi"; } void Csubi::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 Csubi::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); if(!this->m_d) { this->m_cpu->updateFlags(reg, ra, this->m_imm); } } std::string Csubi::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(); }