d2c0a3558fd03a44566302fe7b438385bb9414f0
[calu.git] / 3c_disasm / instr / movf.cpp
1 #include "../Iinstr.hpp"
2
3 class Cmovf : public Iinstr {
4         private:
5                 bool m_type;
6         public:
7                 Cmovf();
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 Cmovf();
23 }
24
25 Iinstr* Cmovf::getNew() {
26         return new Cmovf();
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 Cmovf::Cmovf() : m_type(0)
41 {
42         opcode = B5(01100);
43         name = "movf";
44 }
45
46 void Cmovf::evalInstr()
47 {
48         this->m_type = argbits[18];
49         if(this->m_type) {
50                 name = "movpf";
51         }
52         else {
53                 name = "movsf";
54         }
55         
56         argbits >>= 19;
57         m_rd = this->getRegister(argbits);
58 }
59
60 void Cmovf::execInstr()
61 {
62         //cout << "should exec " << this->toString() << endl;
63         CDat val;
64         if(this->m_type) {
65                 val = this->m_cpu->getFlags();
66         }
67         else {
68                 val = this->m_cpu->getStack();
69         }
70         this->m_cpu->setRegister(this->m_rd, val);
71 }
72
73 std::string Cmovf::toString()
74 {
75         stringstream op;
76         op << this->getName();
77         op << " r" << m_rd;
78         return op.str();
79 }