d264ee3d0c819ddca9445712d2c46d35ce433565
[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                 Iinstr* getNew();
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 Csubi();
21 }
22
23 Iinstr* Csubi::getNew() {
24         return new Csubi();
25 }
26
27 /**
28  * Name:      destroy_instruction
29  * Purpose:   if compiled as shared library, this functions destoys the 
30               instruction object
31
32  * Parameter: IInstruction - the instruction object to delete
33  */
34 extern "C" void destroy_instruction(Iinstr* p) {
35     delete p;
36 }
37
38 Csubi::Csubi()
39 {
40         opcode = B5(00011);
41         name = "subi";
42 }
43
44 void Csubi::evalInstr()
45 {
46         this->m_s = argbits[2];
47         this->m_c = argbits[1];
48         this->m_d = argbits[0];
49
50         argbits >>= 3;
51         dynamic_bitset<> immb = argbits;
52         immb.resize(12);
53         this->m_imm = this->generate12ImmSign(immb.to_ulong());
54
55         argbits >>= 12;
56         m_ra = this->getRegister(argbits);
57
58         argbits >>= 4;
59         m_rd = this->getRegister(argbits);
60 }
61
62 void Csubi::execInstr()
63 {
64         //cout << "should exec " << this->toString() << endl;
65         CDat ra = this->m_cpu->getRegister(m_ra);
66         CDatd reg = ra - this->m_imm;
67         this->m_cpu->setRegister(m_rd, reg);
68         if(!this->m_d) {
69                 this->m_cpu->updateFlags(reg, ra, (~this->m_imm)+1);
70         }
71 }
72
73 std::string Csubi::toString()
74 {
75         stringstream op;
76         op << this->getName();
77
78         if(m_d) op << 'D';
79         if(m_s) op << 'S';
80         if(m_c) op << 'C';
81
82         op << this->getConditionFlag() << " r" << m_rd << ", r" << m_ra << ", " << m_imm;
83
84         return op.str();
85 }