sim: added cmp/i
authorMartin Perner <martin@perner.cc>
Mon, 1 Nov 2010 00:36:04 +0000 (01:36 +0100)
committerMartin Perner <martin@perner.cc>
Mon, 1 Nov 2010 00:36:04 +0000 (01:36 +0100)
3c_disasm/instr/cmp.cpp [new file with mode: 0644]
3c_disasm/instr/cmpi.cpp [new file with mode: 0644]

diff --git a/3c_disasm/instr/cmp.cpp b/3c_disasm/instr/cmp.cpp
new file mode 100644 (file)
index 0000000..7924ed7
--- /dev/null
@@ -0,0 +1,68 @@
+#include "../Iinstr.hpp"
+
+class Ccmp : public Iinstr {
+       public:
+               Ccmp();
+               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 Ccmp();
+}
+
+Iinstr* Ccmp::getNew() {
+       return new Ccmp();
+}
+
+/**
+ * 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;
+}
+
+Ccmp::Ccmp()
+{
+       opcode = B5(11000);
+       name = "cmp";
+}
+
+void Ccmp::evalInstr()
+{
+       argbits >>= 15;
+       m_rb = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_ra = this->getRegister(argbits);
+}
+
+void Ccmp::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDat rb = this->m_cpu->getRegister(m_rb);
+       CDatd val = ra - rb;
+       this->m_cpu->updateFlags(val, ra, rb);
+}
+
+std::string Ccmp::toString()
+{
+       stringstream op;
+       op << this->getName();
+       op << " r" << m_ra << ", r" << m_rb;
+       return op.str();
+}
diff --git a/3c_disasm/instr/cmpi.cpp b/3c_disasm/instr/cmpi.cpp
new file mode 100644 (file)
index 0000000..0de9659
--- /dev/null
@@ -0,0 +1,75 @@
+#include "../Iinstr.hpp"
+
+class Ccmpi : public Iinstr {
+       public:
+               Ccmpi();
+               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 Ccmpi();
+}
+
+Iinstr* Ccmpi::getNew() {
+       return new Ccmpi();
+}
+
+/**
+ * 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;
+}
+
+Ccmpi::Ccmpi()
+{
+       opcode = B5(11001);
+       name = "cmpi";
+}
+
+void Ccmpi::evalInstr()
+{
+       argbits >>= 3;
+       dynamic_bitset<> immb = argbits;
+       immb.resize(16);
+       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+
+       argbits >>= 16;
+       m_ra = this->getRegister(argbits);
+}
+
+void Ccmpi::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDatd reg = ra - this->m_imm;
+       this->m_cpu->updateFlags(reg, ra, this->m_imm);
+}
+
+std::string Ccmpi::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();
+}