public void TestSetAndReadBytes() //MOV AL, BH { byte[] test; RegistersController registry = new GeneralPurposeRegisters(); registry.SetBytesToRegistry("AX", 0, 1); test = registry.GetRegistry("AX"); Assert.AreEqual(BitConverter.ToUInt16(test), 256); registry.SetBytesToRegistry("BH", 0, 255); test = registry.GetRegistry("BX"); Assert.AreEqual(BitConverter.ToUInt16(test), 0); registry.SetBytesToRegistry("CL", 1, 0, 1, 0, 1, 0); test = registry.GetRegistry("CX"); Assert.AreEqual(BitConverter.ToUInt16(test), 1); //Only one argument should set to lower byte. registry.SetBytesToRegistry("DX", 255); test = registry.GetRegistry("DX"); Assert.AreEqual(BitConverter.ToUInt16(test), 255); //We've set 255 to lower byte and now we are setting 2 to higher. //It's becouse we can send even 32bit to DH, then it will take second byte if array may represent 16bit. registry.SetBytesToRegistry("DH", 2); test = registry.GetRegistry("DX"); Assert.AreEqual(BitConverter.ToUInt16(test), (255 + 2 * 256)); }
private void Reset_Click(object sender, RoutedEventArgs e) { generalPurposeRegisters.SetBytesToRegistry("AX", 0); generalPurposeRegisters.SetBytesToRegistry("BX", 0); generalPurposeRegisters.SetBytesToRegistry("CX", 0); generalPurposeRegisters.SetBytesToRegistry("DX", 0); Output.Text = "General purpose registers cleared."; }
public void TestXCHG() { GeneralPurposeRegisters registersMock = new GeneralPurposeRegisters(); LoggerMock loggerMock = new LoggerMock(); RegistryCommander registryCommand = new RegistryCommander(loggerMock); XCHG xchg = new XCHG(registersMock); MOV mov = new MOV(registersMock); AssignToRegistry assignTo = new AssignToRegistry(registersMock); registryCommand.AddHandler(xchg); registryCommand.AddHandler(mov); registryCommand.AddHandler(assignTo); byte[] first; byte[] second; registersMock.SetBytesToRegistry("AX", BitConverter.GetBytes(Convert.ToUInt16(256))); registersMock.SetBytesToRegistry("BX", BitConverter.GetBytes(Convert.ToUInt16(255))); registryCommand.InputCommand("XchG aX, Bx"); first = registersMock.GetRegistry("AX"); second = registersMock.GetRegistry("BX"); Assert.AreEqual(first[0], 255); Assert.AreEqual(first[1], 0); Assert.AreEqual(second[0], 0); Assert.AreEqual(second[1], 1); Assert.AreEqual(loggerMock.outputResult, "AX exchanged with BX."); registryCommand.InputCommand("xchG al, cl"); first = registersMock.GetRegistry("AX"); second = registersMock.GetRegistry("CX"); Assert.AreEqual(first[0], 0); Assert.AreEqual(first[1], 0); Assert.AreEqual(second[0], 255); Assert.AreEqual(second[1], 0); Assert.AreEqual(loggerMock.outputResult, "AL exchanged with CL."); registersMock.SetBytesToRegistry("DX", BitConverter.GetBytes(65535)); registryCommand.InputCommand("XchG bh, dh"); first = registersMock.GetRegistry("BX"); second = registersMock.GetRegistry("DX"); Assert.AreEqual(first[0], 0); Assert.AreEqual(first[1], 255); Assert.AreEqual(second[0], 255); Assert.AreEqual(second[1], 1); Assert.AreEqual(loggerMock.outputResult, "BH exchanged with DH."); registryCommand.InputCommand("xchg cx, dx"); first = registersMock.GetRegistry("CX"); second = registersMock.GetRegistry("DX"); Assert.AreEqual(first[0], 255); Assert.AreEqual(first[1], 1); Assert.AreEqual(second[0], 255); Assert.AreEqual(second[1], 0); Assert.AreEqual(loggerMock.outputResult, "CX exchanged with DX."); registryCommand.InputCommand("xchG dl, ch"); first = registersMock.GetRegistry("DX"); second = registersMock.GetRegistry("CX"); Assert.AreEqual(first[0], 1); Assert.AreEqual(first[1], 0); Assert.AreEqual(second[0], 255); Assert.AreEqual(second[1], 255); Assert.AreEqual(loggerMock.outputResult, "DL exchanged with CH."); }