b77450c30e7b2cb055189168c571b18beb245797
[calu.git] / 3c_disasm / instr / ldw.cpp
1 #include "../Iinstr.hpp"
2
3
4 class Cldw : public Iinstr {
5         public:
6                 Cldw();
7                 void evalInstr();
8                 void execInstr();
9                 std::string toString();
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 Cldw();
21 }
22
23 /**
24  * Name:      destroy_instruction
25  * Purpose:   if compiled as shared library, this functions destoys the 
26               instruction object
27
28  * Parameter: IInstruction - the instruction object to delete
29  */
30 extern "C" void destroy_instruction(Iinstr* p) {
31     delete p;
32 }
33
34 Cldw::Cldw()
35 {
36         opcode = B5(01110);
37         name = "ldw";
38 }
39
40 void Cldw::evalInstr()
41 {
42         this->m_s = true;
43
44         dynamic_bitset<> immb = argbits;
45         immb.resize(15);
46         this->m_imm = this->generate15ImmSign(immb.to_ulong());
47
48         argbits >>= 15;
49         m_ra = this->getRegister(argbits);
50         argbits >>= 4;
51         m_rd = this->getRegister(argbits);
52
53 }
54
55 void Cldw::execInstr()
56 {
57         cout << "should exec " << this->toString() << endl;
58 }
59
60 std::string Cldw::toString()
61 {
62         stringstream op;
63         op << this->getName();
64
65         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" <<  m_ra << ")";
66
67         return op.str();
68 }