1 #include "../Iinstr.hpp"
4 class Cldh : 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* Cldh::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 Cldh::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 Cldh::execInstr()
66 //cout << "should exec " << this->toString() << endl;
67 CDat val = this->m_cpu->getRegister(this->m_ra);
69 MEMORY_ADDRESS temp = (val & (~(BYTE_COUNT-1)));
70 CDat offset = val-temp;
72 cerr << "you try to get an invalid halfword!" << endl;
75 val = this->m_cpu->getRAM(temp);
76 val = (val >> (offset*8)) & ( ((1<<16)-1));
77 CDat dest = this->m_cpu->getRegister(this->m_rd);
78 dest = dest & (~((1<<16)-1));
80 this->m_cpu->setRegister(this->m_rd,dest);
83 std::string Cldh::toString()
86 op << this->getName();
88 op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm << "(r" << m_ra << ")";