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