Ejemplo n.º 1
0
        // BIC (Bit Clear) performs a bitwise AND of one value with the complement of a second value. The first value
        // comes from a register. The second value can be either an immediate value or a value from a register, and can
        // be shifted before the BIC operation.
        // BIC can optionally update the condition code flags, based on the result.
        // SYNTAX: BIC{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
        // USES FIELDS: Rd, Rn, RnRegVal operand2
        private void BIC()
        {
            //Console.WriteLine("DataProcessing.BIC(): is a bic inst");
            // Immediate
            if (bit25 == true)
            {
                uint Rn_BIC_Op2 = RnRegVal & (~immediate.getRotatedImmediate());
                registers.updateRegisterN(Rd, Rn_BIC_Op2);
                instructionString += " " + registers.getRegisterName(Rd) + ", " + immediate.getImmString();
            }


            // Register and Immediate Shifted Register
            if (bit25 == false && bit4 == false)
            {
                // do shift on reg (told by Rm) by shiftNum
                reg_and_imm_sh_reg.execute_RegAndImmShReg();

                // do operation requested
                uint shiftedRegUInt = reg_and_imm_sh_reg.getRmRegVal();
                uint Rn_BIC_Op2     = RnRegVal & (~shiftedRegUInt);

                // move shifted register value into into a register
                registers.updateRegisterN(Rd, Rn_BIC_Op2);

                string op2String = reg_and_imm_sh_reg.getOp2String();
                instructionString += " " + registers.getRegisterName(Rd) + ", " + op2String;
            }


            // Register Shifted Register
            if (bit25 == false && bit4 == true)
            {
                //Console.WriteLine("DataProcesing.BIC(): inst. is a Register Shifted Register ");
                reg_sh_reg.execute_RegShReg();

                // move rototed reg val by reg
                uint shiftedRegUInt = reg_sh_reg.getShiftedRegUInt();
                uint Rn_BIC_Op2     = RnRegVal & (~shiftedRegUInt);
                registers.updateRegisterN(Rd, shiftedRegUInt);

                string op2String = reg_sh_reg.getOp2String();
                instructionString += " " + registers.getRegisterName(Rd) + ", " + op2String;
            }
        }
Ejemplo n.º 2
0
        // FUNCTION: deter
        public void decodeLaS()
        {
            // check bit 25 on instruction to determine if it this instruction has
            // an offset: immediate or immediate shifted register
            bit_25 = memory.TestFlag(instructAddress, 25);

            // update fields: PUBWL
            P = memory.TestFlag(instructAddress, 24);
            U = memory.TestFlag(instructAddress, 23);
            B = memory.TestFlag(instructAddress, 22);
            W = memory.TestFlag(instructAddress, 21);
            L = memory.TestFlag(instructAddress, 20);
            updateInstructionStringWithInstructionName();

            // update field Rn
            Rn = (instruction >> 16) & 0xf;

            // update field RnRegVal
            // if Rn is PC, then RnRegVal should be currentAddress + 8 bytes. else it it's the content of register Rn
            if (Rn == 15)
            {
                RnRegVal = instructAddress + 8;
            }
            else
            {
                RnRegVal = registers.getRegNValue(Rn);
            }

            // update field Rd
            Rd = (instruction >> 12) & 0xf;

            if (bit_25 == false) // OFFSET IS IMMEDIATE. Decode 12 bit op2 immediate
            {
                // update field _12bitImmediate
                _12bitImmediate = instruction & 0xfff;

                if (U) // Immediate is positive
                {
                    effectiveAddress = RnRegVal + _12bitImmediate;
                }
                else // Immediate is negative. TODO: check for negative numbers in unsigned subtraction
                {
                    effectiveAddress = RnRegVal - _12bitImmediate;
                }
            }
            else // OFFSET REGISTER SHIFTED REGISTER. Decode 12 bit  op2 register shifted register
            {
                imm_sh_reg = new RegAndImmShReg(memory, registers, instruction, instructAddress);
                imm_sh_reg.decode_RegAndImmShReg();
                imm_sh_reg.execute_RegAndImmShReg(); // calculates RmRegVal field in object by doing shifting bits

                if (U)                               // Immediate is positive
                {
                    effectiveAddress = RnRegVal + imm_sh_reg.getRmRegVal();
                }
                else // Immediate is negative. TODO: check for negative numbers in unsigned subtraction
                {
                    effectiveAddress = RnRegVal - imm_sh_reg.getRmRegVal();
                }
            }
        }