public void Test_POP(byte opcode) { ushort sp = 0x4242; byte lsbData = 0xFF; byte msbData = 0x11; var expectedState = new CpuState(); expectedState.StackPointer = (ushort)(sp + 2); switch (opcode) { case 0xC1: expectedState.Registers.BC = (ushort)((msbData << 8) | lsbData); break; case 0xD1: expectedState.Registers.DE = (ushort)((msbData << 8) | lsbData); break; case 0xE1: expectedState.Registers.HL = (ushort)((msbData << 8) | lsbData); break; case 0xF1: expectedState.Registers.F = lsbData; expectedState.Registers.A = msbData; break; } var actualState = new CpuState(); actualState.StackPointer = sp; var memoryMock = new Mock <IRandomAccessMemory>(); memoryMock.Setup(m => m.ReadByte(sp)).Returns(lsbData); memoryMock.Setup(m => m.ReadByte((ushort)(sp + 1))).Returns(msbData); var instruction = new POP(); instruction.Initialize(opcode); //act while (!instruction.IsFetchNecessary()) { instruction.ExecuteCycle(actualState, memoryMock.Object); } //assert TestHelper.AssertCpuState(expectedState, actualState); memoryMock.Verify(m => m.WriteByte(It.IsAny <ushort>(), It.IsAny <byte>()), Times.Never); }