#include "../Iinstr.hpp" class Cstackop : public Iinstr { char m_typ; public: Cstackop(); 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 Cstackop(); } Iinstr* Cstackop::getNew() { return new Cstackop(); } /** * 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; } Cstackop::Cstackop() : m_typ(0) { opcode = B5(01011); name = "stackop"; } void Cstackop::evalInstr() { argbits >>= 17; dynamic_bitset<> type = argbits; type.resize(2); this->m_typ = type.to_ulong(); switch(this->m_typ) { case 0: this->name = "pop"; break; case 1: this->name = "disc"; break; case 2: this->name = "fetch"; break; case 3: this->name = "push"; break; default: cerr << "What have you done? 2 bits that have more than 4 values?!" << endl; } argbits >>= 2; m_rd = this->getRegister(argbits); } void Cstackop::execInstr() { CDat sp = this->m_cpu->getStack(); switch(this->m_typ) { case 0: sp += 4; this->m_cpu->setRegister(m_rd, this->m_cpu->getRAM(sp)); break; case 1: sp += 4; break; case 2: this->m_cpu->setRegister(m_rd, this->m_cpu->getRAM(sp)); break; case 3: this->m_cpu->setRAM(sp, this->m_cpu->getRegister(m_rd)); sp -= 4; break; default: cerr << "What have you done? 2 bits that have more than 4 values?!" << endl; } this->m_cpu->setStack(sp); } std::string Cstackop::toString() { stringstream op; op << this->getName(); op << this->getConditionFlag(); op << " r" << m_rd; return op.str(); }