def test_scenario1(values):
    """Test SRC instruction functionality."""
    chip_test = Processor()
    chip_base = Processor()

    registerpair = values[0]
    value = values[1]
    # Set up chip conditions prior to commencement of test
    insert_registerpair(chip_test, registerpair, value)
    chip_test.PROGRAM_COUNTER = 0

    # Perform the instruction under test:
    Processor.src(chip_test, registerpair)

    # Simulate conditions at end of instruction in base chip
    chip_base.PROGRAM_COUNTER = 0
    chip_base.increment_pc(1)
    insert_registerpair(chip_base, registerpair, value)
    chip_base.COMMAND_REGISTER = Processor.decimal_to_binary(8, value)

    # Make assertions that the base chip is now at the same state as
    # the test chip which has been operated on by the instruction under test.

    assert chip_test.read_program_counter() == chip_base.read_program_counter()
    assert chip_test.COMMAND_REGISTER == chip_base.COMMAND_REGISTER

    # Pickling each chip and comparing will show equality or not.
    assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
Ejemplo n.º 2
0
def test_validate_instruction(register):
    """Ensure instruction's characteristics are valid."""
    chip_test = Processor()
    # Validate the instruction's opcode and characteristics:
    op = chip_test.INSTRUCTIONS[144 + register]
    known = {
        "opcode": 144 + register,
        "mnemonic": "sub(" + str(register) + ")",
        "exe": 10.8,
        "bits": ["1001", Processor.decimal_to_binary(4, register)],
        "words": 1
    }  # noqa
    assert op == known
Ejemplo n.º 3
0
def msg_acc(chip: Processor) -> None:
    acc = chip.read_accumulator()
    print('Accumulator : ' + str(acc) + '  (0b ' +
          str(Processor.decimal_to_binary(4, acc)) + ')')