6936f52265a6c1fba7bfa9b6af6752fcb1208850
[calu.git] / 3c_disasm / instr / sub.cpp
1 #include "../Iinstr.hpp"
2
3 class Csub : public Iinstr {
4         public:
5                 Csub();
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 Csub();
21 }
22
23 Iinstr* Csub::getNew() {
24         return new Csub();
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 Csub::Csub()
39 {
40         opcode = B5(00001);
41         name = "sub";
42 }
43
44 void Csub::evalInstr()
45 {
46         this->m_d = argbits[0];
47         this->m_c = argbits[1];
48         
49         argbits >>= 11;
50         m_rb = this->getRegister(argbits);
51
52         argbits >>= 4;
53         m_ra = this->getRegister(argbits);
54
55         argbits >>= 4;
56         m_rd = this->getRegister(argbits);
57 }
58
59 void Csub::execInstr()
60 {
61         //cout << "should exec " << this->toString() << endl;
62         CDat ra = this->m_cpu->getRegister(m_ra);
63         CDat rb = this->m_cpu->getRegister(m_rb);
64         CDatd val = ra - rb;
65         this->m_cpu->setRegister(m_rd, val);
66         if(!this->m_d) {
67                 this->m_cpu->updateFlags(val, ra, (~rb)+1);
68         }
69 }
70
71 std::string Csub::toString()
72 {
73         stringstream op;
74         op << this->getName();
75
76         if(m_d) op << 'D';
77         if(m_c) op << 'C';
78
79         op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
80         return op.str();
81 }