disasm/sim: changed interface, branch => br, features++
[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                 Iinstr* getNew();
11 };
12
13 /**
14  * Name:      create_instruction
15  * Purpose:   if compiled as shared library, this functions creates the 
16               instruction object
17
18  * Returns:   pointer to instruction object
19  */
20 extern "C" Iinstr* create_instruction() {
21     return new Cldi();
22 }
23
24 Iinstr* Cldi::getNew()
25 {
26     return new Cldi();
27 }
28 /**
29  * Name:      destroy_instruction
30  * Purpose:   if compiled as shared library, this functions destoys the 
31               instruction object
32
33  * Parameter: IInstruction - the instruction object to delete
34  */
35 extern "C" void destroy_instruction(Iinstr* p) {
36     delete p;
37 }
38
39 Cldi::Cldi()
40 {
41         opcode = B5(11010);
42         name = "ldi";
43 }
44
45 void Cldi::evalInstr()
46 {
47         this->m_s = argbits[2];
48         this->m_hl = argbits[1];
49
50         argbits >>= 3;
51         dynamic_bitset<> immb = argbits;
52         immb.resize(16);
53         this->m_imm = this->generate16ImmSign(immb.to_ulong());
54
55         argbits >>= 16;
56         m_rd = this->getRegister(argbits);
57 }
58
59 void Cldi::execInstr()
60 {
61         cout << "should exec " << this->toString() << endl;
62         this->m_cpu->setRegister(this->m_rd, this->m_imm);
63 }
64
65 std::string Cldi::toString()
66 {
67         stringstream op;
68         op << this->getName();
69
70         if(m_hl) op << 'H';
71         if(m_s) op << 'S';
72
73         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
74
75         return op.str();
76 }