1 #include "../Iinstr.hpp"
4 class Csth : public Iinstr {
9 std::string toString();
14 * Name: create_instruction
15 * Purpose: if compiled as shared library, this functions creates the
18 * Returns: pointer to instruction object
20 extern "C" Iinstr* create_instruction() {
24 Iinstr* Csth::getNew()
30 * Name: destroy_instruction
31 * Purpose: if compiled as shared library, this functions destoys the
34 * Parameter: IInstruction - the instruction object to delete
36 extern "C" void destroy_instruction(Iinstr* p) {
46 void Csth::evalInstr()
50 dynamic_bitset<> immb = argbits;
52 this->m_imm = this->generate15ImmSign(immb.to_ulong());
55 m_ra = this->getRegister(argbits);
57 m_rd = this->getRegister(argbits);
62 #define AS_HEX std::hex << setw(8) << setfill('0')
64 void Csth::execInstr()
66 //cout << "should exec " << this->toString() << endl;
67 CDat addr = this->m_cpu->getRegister(this->m_ra);
69 MEMORY_ADDRESS temp = (addr & (~(BYTE_COUNT-1)));
70 CDat offset = addr-temp;
72 cerr << "you try to get an invalid halfword!" << endl;
75 CDat val = this->m_cpu->getRAM(temp);
77 val = val & ~( ((1<<16)-1) << (offset*8));
80 CDat source = this->m_cpu->getRegister(this->m_rd);
81 source = (source & (((1<<16)-1))) << (offset*8);
85 this->m_cpu->setRAM(temp, val);
88 std::string Csth::toString()
91 op << this->getName();
93 op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")";