예제 #1
0
        public void TestSetAndReadBytes() //MOV AL, BH
        {
            byte[] test;
            RegistersController registry = new SegmentRegisters();

            registry.SetBytesToRegistry("CS", 0, 1);
            test = registry.GetRegistry("CS");
            Assert.AreEqual(BitConverter.ToUInt16(test), 256);

            registry.SetBytesToRegistry("SS", 0, 255);
            test = registry.GetRegistry("SS");
            Assert.AreEqual(BitConverter.ToUInt16(test), 65280);

            registry.SetBytesToRegistry("DS", 1, 0, 1, 0, 1, 0);
            test = registry.GetRegistry("DS");
            Assert.AreEqual(BitConverter.ToUInt16(test), 1);

            registry.SetBytesToRegistry("ES", 255);
            test = registry.GetRegistry("ES");
            Assert.AreEqual(BitConverter.ToUInt16(test), 255);

            registry.SetBytesToRegistry("ES");
            test = registry.GetRegistry("ES");
            Assert.AreEqual(BitConverter.ToUInt16(test), 255);
        }
예제 #2
0
        public void TestXCHGMemoryRegistry()
        {
            MemoryModel.SetAddressBusLength = 20;
            MemoryModel             memory = MemoryModel.GetInstance();
            GeneralPurposeRegisters generalRegistersMock = new GeneralPurposeRegisters();
            SegmentRegisters        segmentRegistersMock = new SegmentRegisters();
            LoggerMock        loggerMock      = new LoggerMock();
            RegistryCommander registryCommand = new RegistryCommander(loggerMock);

            XCHG             xchg     = new XCHG(generalRegistersMock, segmentRegistersMock);
            MOV              mov      = new MOV(generalRegistersMock, segmentRegistersMock);
            AssignToRegistry assignTo = new AssignToRegistry(generalRegistersMock, segmentRegistersMock);

            registryCommand.AddHandler(xchg);
            registryCommand.AddHandler(mov);
            registryCommand.AddHandler(assignTo);

            registryCommand.InputCommand("MoV AL, FFh");
            registryCommand.InputCommand("MoV [SI + 0], AL");
            registryCommand.InputCommand("MoV AL, 1");
            registryCommand.InputCommand("XCHG [0], AL");
            byte bytetmp = memory.GetMemoryCell(0);

            Assert.AreEqual(bytetmp, 1);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"0\" as decimal.\r\nConverting arguments into effective address 0h.\r\nValue 1h from registry AL exchanged with FF at physical address 0h.\r\n");
            bytetmp = generalRegistersMock.GetRegistry("AL")[0];
            Assert.AreEqual(bytetmp, 255);


            segmentRegistersMock.SetBytesToRegistry("DS", 255);
            registryCommand.InputCommand("MoV CX, FF11h");
            registryCommand.InputCommand("MoV [SI + BP + FFh], CX");
            registryCommand.InputCommand("MoV CX, 2233h");
            registryCommand.InputCommand("XCHG CX, [100h]");
            byte[] word = generalRegistersMock.GetRegistry("CX");
            Assert.AreEqual(word[0], 255);
            Assert.AreEqual(word[1], 0);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"100\" as hexadecimal.\r\nConverting arguments into effective address 100h.\r\nValue 2233h from registry CX exchanged with FF at physical address 10F0h.\r\n");
            word = memory.GetMemoryWord(4336);
            Assert.AreEqual(word[0], 51);
            Assert.AreEqual(word[1], 34);

            MemoryModel.SetAddressBusLength = 0;
        }
예제 #3
0
        public void TestFromToRegistryMemory()
        {
            MemoryModel.SetAddressBusLength = 20;
            MemoryModel             memory = MemoryModel.GetInstance();
            GeneralPurposeRegisters generalRegistersMock = new GeneralPurposeRegisters();
            SegmentRegisters        segmentRegistersMock = new SegmentRegisters();
            LoggerMock        loggerMock      = new LoggerMock();
            RegistryCommander registryCommand = new RegistryCommander(loggerMock);

            XCHG             xchg     = new XCHG(generalRegistersMock, segmentRegistersMock);
            MOV              mov      = new MOV(generalRegistersMock, segmentRegistersMock);
            AssignToRegistry assignTo = new AssignToRegistry(generalRegistersMock, segmentRegistersMock);

            registryCommand.AddHandler(xchg);
            registryCommand.AddHandler(mov);
            registryCommand.AddHandler(assignTo);

            registryCommand.InputCommand("MoV AL, 255");
            registryCommand.InputCommand("MoV [0], AL");
            byte bytetmp = memory.GetMemoryCell(0);

            Assert.AreEqual(bytetmp, 255);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"0\" as decimal.\r\nConverting arguments into effective address 0h.\r\nValue FFh from registry AL assigned to physical address 0h.\r\n");

            segmentRegistersMock.SetBytesToRegistry("DS", 255);
            registryCommand.InputCommand("MoV AH, AAh");
            registryCommand.InputCommand("MoV [FFh], AH");
            bytetmp = memory.GetMemoryCell(4335);
            Assert.AreEqual(bytetmp, 170);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"FF\" as hexadecimal.\r\nConverting arguments into effective address FFh.\r\nValue AAh from registry AH assigned to physical address 10EFh.\r\n");

            segmentRegistersMock.SetBytesToRegistry("DS", 15);
            registryCommand.InputCommand("MoV [0h], AX");
            byte[] word = memory.GetMemoryWord(240);
            Assert.AreEqual(word[0], 255);
            Assert.AreEqual(word[1], 170);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"0\" as hexadecimal.\r\nConverting arguments into effective address 0h.\r\nValue AAFFh from registry AX assigned to physical address F0h.\r\n");

            segmentRegistersMock.SetBytesToRegistry("DS", 0);
            registryCommand.InputCommand("MoV AX, [0h]");
            word = generalRegistersMock.GetRegistry("AX");
            Assert.AreEqual(word[0], 255);
            Assert.AreEqual(word[1], 0);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"0\" as hexadecimal.\r\nConverting arguments into effective address 0h.\r\nValue FFh assigned to registry AX from physical address 0h.\r\n");

            segmentRegistersMock.SetBytesToRegistry("DS", 255);
            registryCommand.InputCommand("MoV AX, [FEh]");
            word = generalRegistersMock.GetRegistry("AX");
            Assert.AreEqual(word[0], 0);
            Assert.AreEqual(word[1], 170);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"FE\" as hexadecimal.\r\nConverting arguments into effective address FEh.\r\nValue AA00h assigned to registry AX from physical address 10EEh.\r\n");

            segmentRegistersMock.SetBytesToRegistry("DS", 15);
            registryCommand.InputCommand("MoV AX, [0h]");
            word = generalRegistersMock.GetRegistry("AX");
            Assert.AreEqual(word[0], 255);
            Assert.AreEqual(word[1], 170);
            Assert.AreEqual(loggerMock.outputResult, "Parsing value \"0\" as hexadecimal.\r\nConverting arguments into effective address 0h.\r\nValue AAFFh assigned to registry AX from physical address F0h.\r\n");

            MemoryModel.SetAddressBusLength = 0;
        }