disasm: alpha version
[calu.git] / 3c_disasm / instr / ldi.cpp
diff --git a/3c_disasm/instr/ldi.cpp b/3c_disasm/instr/ldi.cpp
new file mode 100644 (file)
index 0000000..2c523a1
--- /dev/null
@@ -0,0 +1,70 @@
+#include "../Iinstr.hpp"
+
+
+class Cldi : public Iinstr {
+       public:
+               Cldi();
+               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 Cldi();
+}
+
+/**
+ * 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;
+}
+
+Cldi::Cldi()
+{
+       opcode = B5(11010);
+       name = "ldi";
+}
+
+void Cldi::evalInstr()
+{
+       this->m_s = argbits[2];
+       this->m_hl = argbits[1];
+
+       argbits >>= 3;
+       dynamic_bitset<> immb = argbits;
+       immb.resize(16);
+       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+
+       argbits >>= 16;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cldi::execInstr()
+{
+       cout << "should exec " << this->toString() << endl;
+}
+
+std::string Cldi::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_hl) op << 'H';
+       if(m_s) op << 'S';
+
+       op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
+
+       return op.str();
+}