6420a5517d204fb501df6816243eaef63beb31e5
[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                 Iinstr* getNew();
11 };
12
13 /**
14  * Name:      create_instruction
15  * Purpose:   if compiled as shared library, this functions creates the 
16               instruction object
17
18  * Returns:   pointer to instruction object
19  */
20 extern "C" Iinstr* create_instruction() {
21     return new Cldw();
22 }
23
24 Iinstr* Cldw::getNew()
25 {
26     return new Cldw();
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 Cldw::Cldw()
41 {
42         opcode = B5(01110);
43         name = "ldw";
44 }
45
46 void Cldw::evalInstr()
47 {
48         this->m_s = true;
49
50         dynamic_bitset<> immb = argbits;
51         immb.resize(15);
52         this->m_imm = this->generate15ImmSign(immb.to_ulong());
53
54         argbits >>= 15;
55         m_ra = this->getRegister(argbits);
56         argbits >>= 4;
57         m_rd = this->getRegister(argbits);
58
59 }
60
61 void Cldw::execInstr()
62 {
63         //cout << "should exec " << this->toString() << endl;
64         CDat val = this->m_cpu->getRegister(this->m_ra);
65         val += m_imm;
66         val = this->m_cpu->getRAM(val);
67         this->m_cpu->setRegister(this->m_rd,val);
68 }
69
70 std::string Cldw::toString()
71 {
72         stringstream op;
73         op << this->getName();
74
75         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" <<  m_ra << ")";
76
77         return op.str();
78 }