416812a964d14d18937bac3d98520199142e9c62
[calu.git] / 3c_disasm / instr / movt.cpp
1 #include "../Iinstr.hpp"
2
3 class Cmovt : public Iinstr {
4         private:
5                 bool m_type;
6         public:
7                 Cmovt();
8                 void evalInstr();
9                 void execInstr();
10                 std::string toString();
11                 Iinstr* getNew();
12 };
13
14 /**
15  * Name:      create_instruction
16  * Purpose:   if compiled as shared library, this functions creates the 
17               instruction object
18
19  * Returns:   pointer to instruction object
20  */
21 extern "C" Iinstr* create_instruction() {
22     return new Cmovt();
23 }
24
25 Iinstr* Cmovt::getNew() {
26         return new Cmovt();
27 }
28
29 /**
30  * Name:      destroy_instruction
31  * Purpose:   if compiled as shared library, this functions destoys the 
32               instruction object
33
34  * Parameter: IInstruction - the instruction object to delete
35  */
36 extern "C" void destroy_instruction(Iinstr* p) {
37     delete p;
38 }
39
40 Cmovt::Cmovt() : m_type(0)
41 {
42         opcode = B5(01101);
43         name = "movt";
44 }
45
46 void Cmovt::evalInstr()
47 {
48         this->m_type = argbits[18];
49         if(this->m_type) {
50                 name = "movpt";
51         }
52         else {
53                 name = "movst";
54         }
55         
56         argbits >>= 19;
57         m_rd = this->getRegister(argbits);
58 }
59
60 void Cmovt::execInstr()
61 {
62         //cout << "should exec " << this->toString() << endl;
63         CDat val = this->m_cpu->getRegister(this->m_rd);
64         if(this->m_type) {
65                 this->m_cpu->setFlags(val);
66         }
67         else {
68                 this->m_cpu->setStack(val);
69         }
70 }
71
72 std::string Cmovt::toString()
73 {
74         stringstream op;
75         op << this->getName();
76         op << " r" << m_rd;
77         return op.str();
78 }