private void DecodeRTypeInstruction(Instruction i, string[] registers)
        {
            RTypeInstruction r = (RTypeInstruction)i;

            int[] registersUsed = DetermineRegistersUsed(registers, r.instructionSubType);

            switch (r.instructionSubType)
            {
            case InstructionSubType.arithmetic:
                r.destinationRegister = registersUsed[0];
                r.AddSourceRegister(registersUsed[2]);
                r.AddSourceRegister(registersUsed[1]);
                break;

            case InstructionSubType.jr:
                r.AddSourceRegister(registersUsed[0]);
                break;

            case InstructionSubType.cmp:
                r.AddSourceRegister(registersUsed[1]);
                r.AddSourceRegister(registersUsed[0]);
                break;

            case InstructionSubType.srl:
                r.destinationRegister = registersUsed[0];
                r.AddSourceRegister(registersUsed[2]);
                r.AddSourceRegister(registersUsed[1]);
                break;
            }
        }
 private Instruction SetSBit(Instruction i)
 {
     if (i.instructionType == InstructionType.RType)
     {
         RTypeInstruction r = (RTypeInstruction)i;
         r.sBit = 1;
         return(r);
     }
     else
     {
         DTypeInstruction d = (DTypeInstruction)i;
         d.sBit = 1;
         return(d);
     }
 }
        // Sets the conditional bits
        private void SetConditional(Instruction i, Conditional cond)
        {
            switch (i.instructionType)
            {
            case InstructionType.RType:
                RTypeInstruction r = (RTypeInstruction)i;
                r.cond = cond;
                break;

            case InstructionType.BType:
                BTypeInstruction b = (BTypeInstruction)i;
                b.cond = cond;
                break;

            case InstructionType.DType:
                DTypeInstruction d = (DTypeInstruction)i;
                d.cond = cond;
                break;
            }
        }
        // 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);
        }