aec062b7a6073f47a258c2c1a5782a780c8e1725
[calu.git] / 3c_disasm / instr / stw.cpp
1 #include "../Iinstr.hpp"
2
3
4 class Cstw : public Iinstr {
5         public:
6                 Cstw();
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 Cstw();
22 }
23
24 Iinstr* Cstw::getNew()
25 {
26     return new Cstw();
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 Cstw::Cstw()
41 {
42         opcode = B5(01111);
43         name = "stw";
44 }
45
46 void Cstw::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 Cstw::execInstr()
62 {
63         //cout << "should exec " << this->toString() << endl;
64         CDat val = this->m_cpu->getRegister(this->m_ra);
65         val += m_imm;
66         this->m_cpu->setRAM(val, this->m_cpu->getRegister(this->m_rd));
67 }
68
69 std::string Cstw::toString()
70 {
71         stringstream op;
72         op << this->getName();
73
74         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" <<  m_ra << ")";
75
76         return op.str();
77 }