disasm: alpha version
[calu.git] / 3c_disasm / instr / ldi.cpp
1 #include "../Iinstr.hpp"
2
3
4 class Cldi : public Iinstr {
5         public:
6                 Cldi();
7                 void evalInstr();
8                 void execInstr();
9                 std::string toString();
10 };
11
12 /**
13  * Name:      create_instruction
14  * Purpose:   if compiled as shared library, this functions creates the 
15               instruction object
16
17  * Returns:   pointer to instruction object
18  */
19 extern "C" Iinstr* create_instruction() {
20     return new Cldi();
21 }
22
23 /**
24  * Name:      destroy_instruction
25  * Purpose:   if compiled as shared library, this functions destoys the 
26               instruction object
27
28  * Parameter: IInstruction - the instruction object to delete
29  */
30 extern "C" void destroy_instruction(Iinstr* p) {
31     delete p;
32 }
33
34 Cldi::Cldi()
35 {
36         opcode = B5(11010);
37         name = "ldi";
38 }
39
40 void Cldi::evalInstr()
41 {
42         this->m_s = argbits[2];
43         this->m_hl = argbits[1];
44
45         argbits >>= 3;
46         dynamic_bitset<> immb = argbits;
47         immb.resize(16);
48         this->m_imm = this->generate16ImmSign(immb.to_ulong());
49
50         argbits >>= 16;
51         m_rd = this->getRegister(argbits);
52 }
53
54 void Cldi::execInstr()
55 {
56         cout << "should exec " << this->toString() << endl;
57 }
58
59 std::string Cldi::toString()
60 {
61         stringstream op;
62         op << this->getName();
63
64         if(m_hl) op << 'H';
65         if(m_s) op << 'S';
66
67         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
68
69         return op.str();
70 }