void evalInstr();
void execInstr();
std::string toString();
+ Iinstr* getNew();
};
/**
return new Cbranch();
}
+Iinstr* Cbranch::getNew()
+{
+ return new Cbranch();
+}
/**
* Name: destroy_instruction
* Purpose: if compiled as shared library, this functions destoys the
type.resize(2);
this->m_typ = type.to_ulong();
- switch(m_typ) {
+ switch(this->m_typ) {
case 0:
- this->name = "branch";
+ this->name = "br";
break;
case 1:
this->name = "call";
void Cbranch::execInstr()
{
- cout << "should exec" << this->toString() << endl;
+ //cout << "should exec " << this->toString() << endl;
+ CDat pc = this->m_cpu->getCurPC();
+ switch(this->m_typ) {
+ case 1:
+ {
+ CDat sp = this->m_cpu->getStack();
+ sp -= 4;
+ this->m_cpu->setRAM(sp, this->m_cpu->getNextPC());
+ this->m_cpu->setStack(sp);
+ }
+ case 0:
+ this->m_cpu->setNextPC(pc+this->m_imm);
+ break;
+ case 2:
+ case 3:
+ this->m_cpu->setNextPC(this->m_cpu->getRAM(this->m_cpu->getStack()));
+ this->m_cpu->setStack(this->m_cpu->getStack()+4);
+ break;
+ default:
+ // nothing
+ this->m_cpu->setNextPC(400);
+ }
}
std::string Cbranch::toString()