/// <summary>
        /// FUNCTION:
        ///     -Using instruction field update fields: instructionString, opcode, Rn, Rd, operand2.
        /// </summary>
        public void decodeDP()
        {
            // update field: instructionString, opcode
            opcode = (instruction >> 21) & 0xf;
            updateInstructionName();

            // 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;


            /*  Decode the operand2 of the intruction and update field operand2
             *  Steps to do this:
             *    1. check bits 25 & 4 for operand 2 types
             *    2. if 8 bit immediate
             *            initialize _8BitImmediate object and decode_Imm
             *       if register or immediate shifted register
             *            initialize  RegAndImmShReg object and decode_Imm
             *       if register shifted register
             *            initialize RegShReg object and decode_Imm
             */
            if (bit25 == true)                        // Immediate
            {
                immediate = new Immediate(memory, registers, instruction, instructAddress);
                immediate.decode_Imm();
            }


            if (bit25 == false && bit4 == false) // Register and Immediate Shifted Register
            {
                reg_and_imm_sh_reg = new RegAndImmShReg(memory, registers, instruction, instructAddress);
                reg_and_imm_sh_reg.decode_RegAndImmShReg();
            }

            // TODO: not implemented in sim I
            if (this.bit25 == false && this.bit4 == true)  // Register Shifted Register
            {
                this.reg_sh_reg = new RegShReg(this.memory, this.registers, this.instruction, this.instructAddress);
                this.reg_sh_reg.decode_RegShReg();
            }
        }
        private bool bit4;  //data processing addressing mode flag


        public DataProcessing(Memory _memory, Registers _registers, uint _currentInstruction, uint _currentInstAddress)
        {
            this.instructionString = "Not Found Yet";
            this.instruction       = _currentInstruction;
            this.instructAddress   = _currentInstAddress;

            // initialize operand2 types to null
            this.immediate          = null;
            this.reg_and_imm_sh_reg = null;
            this.reg_sh_reg         = null;

            // hook up registers and mememory object references
            this.registers = _registers;
            this.memory    = _memory;

            // setting up data processing addressing mode flags // -4 because pc gor incremented by 4 bytes when the instruction was fetched
            this.bit25 = memory.TestFlag(registers.getProgramCounter() - 4, 25);  //data processing addressing mode flag
            this.bit4  = memory.TestFlag(registers.getProgramCounter() - 4, 4);   //data processing addressing mode flag
        }
Exemple #3
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();
                }
            }
        }