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