b9b02bfef4b450de938a4f685ee0a669166552c9
[calu.git] / 3c_disasm / instr / cmp.cpp
1 #include "../Iinstr.hpp"
2
3 class Ccmp : public Iinstr {
4         public:
5                 Ccmp();
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 Ccmp();
21 }
22
23 Iinstr* Ccmp::getNew() {
24         return new Ccmp();
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 Ccmp::Ccmp()
39 {
40         opcode = B5(11000);
41         name = "cmp";
42 }
43
44 void Ccmp::evalInstr()
45 {
46         argbits >>= 15;
47         m_rb = this->getRegister(argbits);
48
49         argbits >>= 4;
50         m_ra = this->getRegister(argbits);
51 }
52
53 void Ccmp::execInstr()
54 {
55         //cout << "should exec " << this->toString() << endl;
56         CDat ra = this->m_cpu->getRegister(m_ra);
57         CDat rb = this->m_cpu->getRegister(m_rb);
58         CDatd val = ra - rb;
59         this->m_cpu->updateFlags(val, ra, (~rb)+1);
60 }
61
62 std::string Ccmp::toString()
63 {
64         stringstream op;
65         op << this->getName();
66         op << " r" << m_ra << ", r" << m_rb;
67         return op.str();
68 }