1 #include "../Iinstr.hpp"
3 class Cbranch : public Iinstr {
11 std::string toString();
16 * Name: create_instruction
17 * Purpose: if compiled as shared library, this functions creates the
20 * Returns: pointer to instruction object
22 extern "C" Iinstr* create_instruction() {
26 Iinstr* Cbranch::getNew()
31 * Name: destroy_instruction
32 * Purpose: if compiled as shared library, this functions destoys the
35 * Parameter: IInstruction - the instruction object to delete
37 extern "C" void destroy_instruction(Iinstr* p) {
41 Cbranch::Cbranch() : m_taken(1), m_typ(0)
47 void Cbranch::evalInstr()
49 this->m_s = argbits[0];
50 this->m_taken = argbits[1];
54 dynamic_bitset<> type = argbits;
56 this->m_typ = type.to_ulong();
74 cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
79 dynamic_bitset<> immb = argbits;
81 this->m_imm = this->generate16ImmSign(immb.to_ulong());
85 void Cbranch::execInstr()
87 //cout << "should exec " << this->toString() << endl;
88 CDat pc = this->m_cpu->getCurPC();
92 CDat sp = this->m_cpu->getStack();
94 this->m_cpu->setRAM(sp, this->m_cpu->getNextPC());
95 this->m_cpu->setStack(sp);
98 this->m_cpu->setNextPC(pc+this->m_imm);
102 this->m_cpu->setNextPC(this->m_cpu->getRAM(this->m_cpu->getStack()));
103 this->m_cpu->setStack(this->m_cpu->getStack()+4);
107 this->m_cpu->setNextPC(400);
111 std::string Cbranch::toString()
114 op << this->getName();
118 op << this->getConditionFlag() << (m_taken ? '+' : '-');
120 op << " 0x" << std::hex << m_imm << "(" << std::dec << m_imm << ")";