コード例 #1
0
        /// <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();
            }
        }
コード例 #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();
                }
            }
        }