public void WriteBack() { RegisterFile.WriteReg = BinaryConverter.BitsToInt(MemWb.RegDest); RegisterFile.WrData = MemWb.MemToReg ? MemWb.ReadData : MemWb.Result; RegisterFile.RegWrite = MemWb.RegWrite; RegisterFile.WriteData(); }
public void Decode() { if (IfId.Instruction == null) { return; } var instruction = new Instruction(IfId.Instruction); RegisterFile.ReadReg1 = BinaryConverter.BitsToInt(instruction.Rs); RegisterFile.ReadReg2 = BinaryConverter.BitsToInt(instruction.Rt); _controlUnit.Control(instruction); // Execution Stage Control lines IdEx.RegDest = _controlUnit.RegDest; IdEx.AluSrc = _controlUnit.AluSrc; IdEx.AluOp = _controlUnit.AluOp; // Memory access Stage control lines IdEx.Branch = _controlUnit.Branch; IdEx.MemRead = _controlUnit.MemRead; IdEx.MemWrite = _controlUnit.MemWrite; // Write back Stage control lines IdEx.RegWrite = _controlUnit.RegWrite; IdEx.MemToReg = _controlUnit.MemToReg; IdEx.Pc = IfId.Pc; IdEx.ReadData1 = RegisterFile.ReadData1; IdEx.ReadData2 = RegisterFile.ReadData2; IdEx.Rd = instruction.I15_11; IdEx.Rt = instruction.I20_16; IdEx.Offset = BitwiseOperations.ExtendSign(instruction.I15_0); }
public Instruction(string instruction) { Opcode = BinaryConverter.StringToBits(instruction.Substring(26, 6)); var opcodeComparer = BinaryConverter.BitsToInt(Opcode); switch (opcodeComparer) { case ROpCode: Type = Format.R; Rs = BinaryConverter.StringToBits(instruction.Substring(21, 5)); Rt = BinaryConverter.StringToBits(instruction.Substring(16, 5)); Rd = BinaryConverter.StringToBits(instruction.Substring(11, 5)); Shamt = BinaryConverter.StringToBits(instruction.Substring(6, 5)); Function = BinaryConverter.StringToBits(instruction.Substring(0, 6)); break; case JOpCode: case JOpCode2: Type = Format.J; Offset = BinaryConverter.StringToBits(instruction.Substring(0, 26)); break; default: Type = Format.I; Rs = BinaryConverter.StringToBits(instruction.Substring(21, 5)); Rt = BinaryConverter.StringToBits(instruction.Substring(16, 5)); Offset = BinaryConverter.StringToBits(instruction.Substring(0, 16)); break; } I15_11 = BinaryConverter.StringToBits(instruction.Substring(11, 5)); I20_16 = BinaryConverter.StringToBits(instruction.Substring(16, 5)); I15_0 = BinaryConverter.StringToBits(instruction.Substring(0, 16)); }
public Dictionary <string, string> Map() { return(new Dictionary <string, string> { { "ReadData", ReadData.ToString() }, { "Result", Result.ToString() }, { "RegDest", BinaryConverter.BitsToInt(RegDest).ToString() }, { "RegWrite", RegWrite.ToString() }, { "MemToReg", MemToReg.ToString() } }); }
public Dictionary <string, string> Map() { return(new Dictionary <string, string> { { "PcJump", PcJump.ToString() }, { "ZeroFlag", ZeroFlag.ToString() }, { "Result", Result.ToString() }, { "ReadData2", ReadData2.ToString() }, { "RegDest", BinaryConverter.BitsToInt(RegDest).ToString() }, { "RegWrite", RegWrite.ToString() }, { "MemToReg", MemToReg.ToString() }, { "Branch", Branch.ToString() }, { "MemRead", MemRead.ToString() }, { "MemWrite", MemWrite.ToString() } }); }
public Dictionary <string, string> Map() { return(new Dictionary <string, string> { { "Pc", Pc.ToString() }, { "ReadData1", ReadData1.ToString() }, { "ReadData2", ReadData2.ToString() }, { "Rt", BinaryConverter.BitsToInt(Rt).ToString() }, { "Rd", BinaryConverter.BitsToInt(Rd).ToString() }, { "Offset", BinaryConverter.BitsToInt(Offset).ToString() }, { "RegWrite", RegWrite.ToString() }, { "MemToReg", MemToReg.ToString() }, { "Branch", Branch.ToString() }, { "MemRead", MemRead.ToString() }, { "MemWrite", MemWrite.ToString() }, { "RegDest", RegDest.ToString() }, { "AluOp", BinaryConverter.BitsToInt(AluOp).ToString() }, { "AluSrc", AluSrc.ToString() } }); }
public void Execute() { _alu.Data1 = IdEx.ReadData1; _alu.Data2 = IdEx.AluSrc ? BinaryConverter.BitsToInt(IdEx.Offset) : IdEx.ReadData2; _alu.Compute(IdEx.AluOp); // Memory access Stage control lines ExMem.Branch = IdEx.Branch; ExMem.MemRead = IdEx.MemRead; ExMem.MemWrite = IdEx.MemWrite; // Write back Stage control lines ExMem.RegWrite = IdEx.RegWrite; ExMem.MemToReg = IdEx.MemToReg; ExMem.PcJump = IdEx.Pc + (uint)BinaryConverter.BitsToInt(BitwiseOperations.LogicalShl(IdEx.Offset, 2)); ExMem.ZeroFlag = _alu.ZeroFlag; ExMem.Result = _alu.Result; ExMem.ReadData2 = IdEx.ReadData2; ExMem.RegDest = IdEx.RegDest ? IdEx.Rd : IdEx.Rt; }
public void Compute(BitArray operation) { var opToInt = BinaryConverter.BitsToInt(operation); if (opToInt == BinaryConverter.BitsToInt(AluOps.AND)) { Result = Data1 & Data2; } else if (opToInt == BinaryConverter.BitsToInt(AluOps.OR)) { Result = Data1 | Data2; } else if (opToInt == BinaryConverter.BitsToInt(AluOps.ADD)) { Result = Data1 + Data2; } else if (opToInt == BinaryConverter.BitsToInt(AluOps.SUB)) { Result = Data1 - Data2; } ZeroFlag = (Result == 0); }