a6967e490999e48a3a44366f337472a3c1c55454
[calu.git] / 3c_disasm / instr / add.cpp
1 #include "../Iinstr.hpp"
2
3 class Cadd : public Iinstr {
4         public:
5                 Cadd();
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 Cadd();
21 }
22
23 Iinstr* Cadd::getNew() {
24         return new Cadd();
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 Cadd::Cadd()
39 {
40         opcode = B5(00000);
41         name = "add";
42 }
43
44 void Cadd::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 Cadd::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);
68         }
69 }
70
71 std::string Cadd::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 << this->getConditionFlag() << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
80         return op.str();
81 }