disasm: alpha version
[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 };
10
11 /**
12  * Name:      create_instruction
13  * Purpose:   if compiled as shared library, this functions creates the 
14               instruction object
15
16  * Returns:   pointer to instruction object
17  */
18 extern "C" Iinstr* create_instruction() {
19     return new Cadd();
20 }
21
22 /**
23  * Name:      destroy_instruction
24  * Purpose:   if compiled as shared library, this functions destoys the 
25               instruction object
26
27  * Parameter: IInstruction - the instruction object to delete
28  */
29 extern "C" void destroy_instruction(Iinstr* p) {
30     delete p;
31 }
32
33 Cadd::Cadd()
34 {
35         opcode = B5(00000);
36         name = "add";
37 }
38
39 void Cadd::evalInstr()
40 {
41         this->m_d = argbits[0];
42         this->m_c = argbits[1];
43         
44         argbits >>= 11;
45         m_rb = this->getRegister(argbits);
46
47         argbits >>= 4;
48         m_ra = this->getRegister(argbits);
49
50         argbits >>= 4;
51         m_rd = this->getRegister(argbits);
52 }
53
54 void Cadd::execInstr()
55 {
56         cout << "should exec" << this->toString() << endl;
57 }
58
59 std::string Cadd::toString()
60 {
61         stringstream op;
62         op << this->getName();
63
64         if(m_d) op << 'D';
65         if(m_c) op << 'C';
66
67         op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
68         return op.str();
69 }