private void DecodeDTypeInstruction(Instruction i, string[] registers) { DTypeInstruction d = (DTypeInstruction)i; int[] registersUsed = DetermineRegistersUsed(registers, d.instructionSubType); switch (d.instructionSubType) { case InstructionSubType.lw: d.destinationRegister = registersUsed[0]; d.immediateValue = registersUsed[1]; d.sourceRegister = registersUsed[2]; break; case InstructionSubType.sw: d.destinationRegister = registersUsed[0]; d.immediateValue = registersUsed[1]; d.sourceRegister = registersUsed[2]; break; case InstructionSubType.addi: d.destinationRegister = registersUsed[0]; d.sourceRegister = registersUsed[1]; d.immediateValue = registersUsed[2]; break; //case InstructionSubType.si: // 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); }