public void TestSW() { var cpu = new CPU(); cpu.RegWrite(5, 123456789); cpu.RegWrite(6, 4 << 2); const string instr = "sw $5, 4($6)"; var instructionAdd = new SW(instr, 0, 5, 4, 6); cpu.AddInstruction(instructionAdd); var expectedRecords = new List<ExecutionRecordList>(); int clockCycle = 0; cpu.RunClock(); expectedRecords.Add(new ExecutionRecordList()); expectedRecords[clockCycle].Add(new ExecutionRecord(ExecutionType.Fetch, instr, 0, null)); clockCycle++; Assert.IsTrue(expectedRecords.SequenceEqual(cpu.ExecutionRecords)); cpu.RunClock(); expectedRecords.Add(new ExecutionRecordList()); expectedRecords[clockCycle].Add(new ExecutionRecord(ExecutionType.Decode, "SW: rs = $6, rt = $5, imm = 4", 0, null)); clockCycle++; Assert.IsTrue(expectedRecords.SequenceEqual(cpu.ExecutionRecords)); cpu.RunClock(); expectedRecords.Add(new ExecutionRecordList()); expectedRecords[clockCycle].Add(new ExecutionRecord(ExecutionType.Execute, "SW Address = 16 + 4 = 20", 0, null)); clockCycle++; Assert.IsTrue(expectedRecords.SequenceEqual(cpu.ExecutionRecords)); cpu.RunClock(); expectedRecords.Add(new ExecutionRecordList()); expectedRecords[clockCycle].Add(new ExecutionRecord(ExecutionType.Memory, "Value written in memory = 123456789", 0, null)); clockCycle++; Assert.IsTrue(expectedRecords.SequenceEqual(cpu.ExecutionRecords)); //Test value inside register file Assert.AreEqual(123456789, cpu.Load((4 << 2) + 4)); Assert.AreEqual(clockCycle, cpu.ClockCycle); }