public void TestSetAndReadBytes() //MOV AL, BH { byte[] test; RegistersController registry = new PointerRegisters(); registry.SetBytesToRegistry("BP", 0, 1); test = registry.GetRegistry("BP"); Assert.AreEqual(BitConverter.ToUInt16(test), 256); registry.SetBytesToRegistry("SP", 0, 255); test = registry.GetRegistry("SP"); Assert.AreEqual(BitConverter.ToUInt16(test), 65280); registry.SetBytesToRegistry("BP", 1, 0, 1, 0, 1, 0); test = registry.GetRegistry("BP"); Assert.AreEqual(BitConverter.ToUInt16(test), 1); registry.SetBytesToRegistry("SP", 255); test = registry.GetRegistry("SP"); Assert.AreEqual(BitConverter.ToUInt16(test), 255); registry.SetBytesToRegistry("BP"); test = registry.GetRegistry("BP"); Assert.AreEqual(BitConverter.ToUInt16(test), 1); }
public void TestPOP() { MemoryModel.SetAddressBusLength = 20; MemoryModel memory = MemoryModel.GetInstance(); GeneralPurposeRegisters generalRegistersMock = new GeneralPurposeRegisters(); SegmentRegisters segmentRegistersMock = new SegmentRegisters(); PointerRegisters pointerRegistersMock = new PointerRegisters(); LoggerMock loggerMock = new LoggerMock(); RegistryCommander registryCommand = new RegistryCommander(loggerMock); POP pop = new POP(generalRegistersMock, pointerRegistersMock, segmentRegistersMock); PUSH push = new PUSH(generalRegistersMock, pointerRegistersMock, segmentRegistersMock); XCHG xchg = new XCHG(generalRegistersMock, segmentRegistersMock); MOV mov = new MOV(generalRegistersMock, segmentRegistersMock); AssignToRegistry assignTo = new AssignToRegistry(generalRegistersMock, pointerRegistersMock, segmentRegistersMock); registryCommand.AddHandler(pop); registryCommand.AddHandler(push); registryCommand.AddHandler(xchg); registryCommand.AddHandler(mov); registryCommand.AddHandler(assignTo); byte[] word; registryCommand.InputCommand("ax 1122"); registryCommand.InputCommand("push ax"); registryCommand.InputCommand("pop cx"); word = generalRegistersMock.GetRegistry("CX"); Assert.AreEqual(34, word[0]); Assert.AreEqual(17, word[1]); Assert.AreEqual("Value 1122h from physical address 0h popped from stack to registry CX.\r\n", loggerMock.outputResult); word = pointerRegistersMock.GetRegistry("SP"); Assert.AreEqual(0, word[0]); registryCommand.InputCommand("ax FFEE"); registryCommand.InputCommand("bx AA99"); registryCommand.InputCommand("SS FF"); registryCommand.InputCommand("push ax"); registryCommand.InputCommand("push bx"); registryCommand.InputCommand("pop dx"); word = generalRegistersMock.GetRegistry("DX"); Assert.AreEqual(153, word[0]); Assert.AreEqual(170, word[1]); Assert.AreEqual("Value AA99h from physical address FF2h popped from stack to registry DX.\r\n", loggerMock.outputResult); word = pointerRegistersMock.GetRegistry("SP"); Assert.AreEqual(2, word[0]); }
public void TestPUSH() { MemoryModel.SetAddressBusLength = 20; MemoryModel memory = MemoryModel.GetInstance(); GeneralPurposeRegisters generalRegistersMock = new GeneralPurposeRegisters(); SegmentRegisters segmentRegistersMock = new SegmentRegisters(); PointerRegisters pointerRegistersMock = new PointerRegisters(); LoggerMock loggerMock = new LoggerMock(); RegistryCommander registryCommand = new RegistryCommander(loggerMock); PUSH push = new PUSH(generalRegistersMock, pointerRegistersMock, segmentRegistersMock); XCHG xchg = new XCHG(generalRegistersMock, segmentRegistersMock); MOV mov = new MOV(generalRegistersMock, segmentRegistersMock); AssignToRegistry assignTo = new AssignToRegistry(generalRegistersMock, pointerRegistersMock, segmentRegistersMock); registryCommand.AddHandler(push); registryCommand.AddHandler(xchg); registryCommand.AddHandler(mov); registryCommand.AddHandler(assignTo); byte[] word; registryCommand.InputCommand("ax 1122"); registryCommand.InputCommand("push ax"); word = memory.GetMemoryWord(0); Assert.AreEqual(word[0], 34); Assert.AreEqual(word[1], 17); Assert.AreEqual("Value 1122h from registry AX pushed on stack with physical address 0h.\r\n", loggerMock.outputResult); word = pointerRegistersMock.GetRegistry("SP"); Assert.AreEqual(word[0], 2); registryCommand.InputCommand("ax FFEE"); registryCommand.InputCommand("bx AA99"); registryCommand.InputCommand("SS FF"); registryCommand.InputCommand("push ax"); registryCommand.InputCommand("push bx"); word = memory.GetMemoryWord(4083); Assert.AreEqual(word[0], 255); Assert.AreEqual(word[1], 153); Assert.AreEqual("Value AA99h from registry BX pushed on stack with physical address FF4h.\r\n", loggerMock.outputResult); word = pointerRegistersMock.GetRegistry("SP"); Assert.AreEqual(word[0], 6); }