コード例 #1
0
        private void DecodeJTypeInstruction(Instruction i, string[] regAndImmed)
        {
            JTypeInstruction j = (JTypeInstruction)i;

            int[] regAndImmedValue = DetermineRegistersUsed(regAndImmed, j.instructionSubType);

            if (j.instructionSubType == InstructionSubType.li)
            {
                j.destinationRegister = regAndImmedValue[0];
                j.immediateValue      = regAndImmedValue[1];
            }
            else
            {
                j.immediateValue = regAndImmedValue[0];
            }
        }
コード例 #2
0
        // Determines which type of instruction to create based on if instruction is in a specific dictionary
        // and creates a new instruction of that type. Instructions are in the form of lw, sw, add, bal, etc.
        private Instruction CreateCorrectTypeOfInstruction(string instruction, int lineNum)
        {
            InstructionSubType subType;
            Instruction        i = null;

            if (JInstructions.TryGetValue(instruction, out subType))
            {
                JTypeInstruction j = new JTypeInstruction();
                j.instructionSubType = subType;
                i = j;
            }
            else if (BInstructions.TryGetValue(instruction, out subType))
            {
                BTypeInstruction b = new BTypeInstruction();
                b.instructionSubType = subType;
                i = b;
            }
            else if (DInstructions.TryGetValue(instruction, out subType))
            {
                DTypeInstruction d = new DTypeInstruction();
                d.instructionSubType = subType;
                i = d;
            }
            else if (RInstructions.TryGetValue(instruction, out subType))
            {
                RTypeInstruction r = new RTypeInstruction();
                r.instructionSubType = subType;
                // Determines what the OpX bits should be based on the instruction given in the form add, sub, xor, etc.
                r.OpX = (RTypeInstruction.Opx)Enum.Parse(typeof(RTypeInstruction.Opx), instruction);
                i     = r;
            }
            else
            {
                throw new InvalidInstructionException(String.Format("The instruction on line {0} is an invalid instruction.", lineNum));
            }

            return(i);
        }