disasm: alpha version
[calu.git] / 3c_disasm / instr / subi.cpp
diff --git a/3c_disasm/instr/subi.cpp b/3c_disasm/instr/subi.cpp
new file mode 100644 (file)
index 0000000..a988f81
--- /dev/null
@@ -0,0 +1,74 @@
+#include "../Iinstr.hpp"
+
+class Csubi : public Iinstr {
+       public:
+               Csubi();
+               void evalInstr();
+               void execInstr();
+               std::string toString();
+};
+
+/**
+ * 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();
+}
+
+/**
+ * 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;
+}
+
+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();
+}