2a80bf78cbb6338427d2127aff4e768eb42f0122
[calu.git] / 3c_disasm / instr / cmpi.cpp
1 #include "../Iinstr.hpp"
2
3 class Ccmpi : public Iinstr {
4         public:
5                 Ccmpi();
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 Ccmpi();
21 }
22
23 Iinstr* Ccmpi::getNew() {
24         return new Ccmpi();
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 Ccmpi::Ccmpi()
39 {
40         opcode = B5(11001);
41         name = "cmpi";
42 }
43
44
45 void Ccmpi::evalInstr()
46 {
47         argbits >>= 3;
48         dynamic_bitset<> immb = argbits;
49         immb.resize(16);
50         this->m_imm = this->generate16ImmSign(immb.to_ulong());
51
52         argbits >>= 16;
53         m_ra = this->getRegister(argbits);
54 }
55
56 void Ccmpi::execInstr()
57 {
58         //cout << "should exec " << this->toString() << endl;
59         CDat ra = this->m_cpu->getRegister(m_ra);
60         CDatd reg = ra - this->m_imm;
61         this->m_cpu->updateFlags(reg, ra, (~this->m_imm)+1);
62 }
63
64 std::string Ccmpi::toString()
65 {
66         stringstream op;
67         op << this->getName();
68
69         if(m_d) op << 'D';
70         if(m_s) op << 'S';
71         if(m_c) op << 'C';
72
73         op << this->getConditionFlag() << " r" << m_ra << ", " << m_imm;
74
75         return op.str();
76 }