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 void TestThatShiftLeft1PositionAndFillShiftsAndAdds0() { var value = Convert.ToUInt32("11101101000111001001000011000011", 2); var expectedResult = Convert.ToUInt32("11011010001110010010000110000110", 2); var result = BitwiseOperations.ExtractSecondMostSignificantBitAndFill(value, 0); Assert.AreEqual(expectedResult, result); }
public void TestThatWhenFillBitIs1ExtractSecondMostSignificantBitAndFillReturnsExpectedValue() { var value = Convert.ToUInt32("11101101000111001001000011000011", 2); var expectedResult = Convert.ToUInt32("11011010001110010010000110000111", 2); var result = BitwiseOperations.ExtractSecondMostSignificantBitAndFill(value, 1); Assert.AreEqual(expectedResult, result); }
public void TestThatWhenValueStartsWith1GetMostSignificantInPlaceReturnsExpectedValue() { var value = Convert.ToUInt32("11101101000111001001000011000011", 2); var expectedResult = Convert.ToUInt32("10000000000000000000000000000000", 2); var result = BitwiseOperations.GetMostSignificantInPlace(value); Assert.AreEqual(expectedResult, result); }
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; }
static void Main(string[] args) { int n = 0; for (; ;) { Console.WriteLine("Выберите библиотеку для теста:"); Console.WriteLine("1: Сдвиг влево, Сдвиг вправо"); Console.WriteLine("====================================="); n = int.Parse(Console.ReadLine()); Console.WriteLine("Ваш выбор = {0}. Запускаем тест", n); Console.WriteLine(); switch (n) { case 1: BitwiseOperations.LeftRight(4, 1); BitwiseOperations.Assignment(2); break; } } }
private static void Main(string[] args) { //The << operator shifts a number to the left by a specified number of bits. //Zeroes are added to the least significant bits. BitwiseOperations.BitShiftToLeft(2, 4); //perator shifts a number to the right by a specified number of bits. //The first operand is shifted to right by the number of bits specified by second operand. //BitwiseOperations.BitShiftToRight(16, 4); //Byte inversing turns 0 into 1 and 1 into 0. For example number 2 converted into 32-bits (basic integer has 32 bytes) binary is 00000000000000000000000000000010. //That number inverted is 11111111111111111111111111111101 which in decimals is -3. //BitwiseOperations.InverseBytes(2); //If either of the bits on the same place is 1, the result is 1. Otherwise the result is 0. //If value1 in binary 1001 (9 in decimal) and value2 is 1010 (10) //after OR operation value is 1011 (11) //BitwiseOperations.BitwiseOR(521, 23); //If either of the bits is 0, the result is 0. Otherwise the result is 1. //If value1 in binary 1001 (9 in decimal) and value2 is 1010 (10) //after OR operation value is 1000 (8) //BitwiseOperations.BitwiseAND(9, 10); //If the corresponding bits are same, the result is 0. If the corresponding bits are different, the result is 1. //If value1 in binary 1001 (9 in decimal) and value2 is 1010 (10) //after XOR operation value is 0011 (3) //BitwiseOperations.BitwiseXOR(9, 10); }
public void Arrange() { bitwiseOperations = new BitwiseOperations(); }