sim: added cmp/i
[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 void Ccmpi::evalInstr()
45 {
46         argbits >>= 3;
47         dynamic_bitset<> immb = argbits;
48         immb.resize(16);
49         this->m_imm = this->generate16ImmSign(immb.to_ulong());
50
51         argbits >>= 16;
52         m_ra = this->getRegister(argbits);
53 }
54
55 void Ccmpi::execInstr()
56 {
57         //cout << "should exec " << this->toString() << endl;
58         CDat ra = this->m_cpu->getRegister(m_ra);
59         CDatd reg = ra - this->m_imm;
60         this->m_cpu->updateFlags(reg, ra, this->m_imm);
61 }
62
63 std::string Ccmpi::toString()
64 {
65         stringstream op;
66         op << this->getName();
67
68         if(m_d) op << 'D';
69         if(m_s) op << 'S';
70         if(m_c) op << 'C';
71
72         op << this->getConditionFlag() << " r" << m_rd << ", r" << m_ra << ", " << m_imm;
73
74         return op.str();
75 }