1 #include "../Iinstr.hpp"
3 class Cshift : 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* Cshift::getNew()
29 * Name: destroy_instruction
30 * Purpose: if compiled as shared library, this functions destoys the
33 * Parameter: IInstruction - the instruction object to delete
35 extern "C" void destroy_instruction(Iinstr* p) {
39 Cshift::Cshift() : m_typ(0)
45 void Cshift::evalInstr()
47 this->m_d = argbits[0];
48 this->m_c = argbits[1];
51 dynamic_bitset<> type = argbits;
53 this->m_typ = type.to_ulong();
57 cerr << "INVALID shift type, using logic left shift!" << endl;
69 cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
73 dynamic_bitset<> immb = argbits;
75 this->m_imm = immb.to_ulong();
77 m_ra = this->getRegister(argbits);
79 m_rd = this->getRegister(argbits);
82 void Cshift::execInstr()
84 CDatd val = this->m_cpu->getRegister(m_ra);
88 // this->name = "lls";
89 for(unsigned int i = 0; i < m_imm; i++) {
94 this->m_cpu->updateCarry(((val >> BIT_LEN) & 0x1) != 0);
98 // this->name = "lrs";
100 bool carry = this->m_cpu->getCarry();
101 for(unsigned int i = 0; i < m_imm; i++) {
105 //if user wants carry, and carry is set
106 if(this->m_c && carry) {
108 val |= (CDat)(1<<(BIT_LEN-1));
112 val &= (~(1<<(BIT_LEN-1)));
118 // this->name = "ars";
119 //>> is a ars, but val is CDatd => we have to set the MSB manually
121 bool msb = (val & (1<<(BIT_LEN-1)) >> (BIT_LEN-1));
122 for(unsigned int i = 0; i < m_imm; i++) {
126 val |= (CDat)(1<<(BIT_LEN-1));
130 val &= (~(1<<(BIT_LEN-1)));
136 cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
138 this->m_cpu->setRegister(m_rd, val);
141 std::string Cshift::toString()
144 op << this->getName();
148 op << this->getConditionFlag();
149 op << " r" << m_rd << ", r" << m_ra << ", " << m_imm;