コード例 #1
0
def test_load_rect():
    with open("examples/RectL.asm") as f:
        ops1, symbols1, statics1 = project_06.assemble(f)
    assert len(ops1) == 25
    assert symbols1 == {}
    assert statics1 == {}

    with open("examples/Rect.asm") as f:
        ops2, symbols2, statics2 = project_06.assemble(f)
    assert len(ops2) == 25
    assert symbols2 == {"LOOP": 10, "INFINITE_LOOP": 23}
    assert statics2 == {"counter": 16, "address": 17}

    assert ops2 == ops1
コード例 #2
0
def test_load_pong():
    with open("examples/PongL.asm") as f:
        ops1, symbols1, statics1 = project_06.assemble(f)
    assert len(ops1) == 27483
    assert symbols1 == {}
    assert statics1 == {}

    with open("examples/Pong.asm") as f:
        ops2, symbols2, statics2 = project_06.assemble(f)
    assert len(ops2) == 27483
    assert len(symbols2) == 882
    assert symbols2["main.main"] == 3837
    assert len(statics2) == 14
    assert statics2["ponggame.0"] == 16
    assert statics2["screen.0"] == 29

    assert ops2 == ops1
コード例 #3
0
def init_sp(computer, address=256):
    """Initialize SP, which may or may not be stored in RAM."""

    pgm, _, _ = project_06.assemble([
        f"@{address}",
        "D=A",
        "@SP",
        "M=D",
    ])
    computer.init_rom(pgm)
    while computer.pc < len(pgm):
        computer.ticktock()

    computer.reset = True
    computer.ticktock()
    computer.reset = False
コード例 #4
0
def test_load_max_no_symbols():
    with open("examples/MaxL.asm") as f:
        ops, symbols, statics = project_06.assemble(f)
    assert ops == MAX_PROGRAM
    assert symbols == {}
    assert statics == {}
コード例 #5
0
def test_load_add():
    with open("examples/Add.asm") as f:
        ops, symbols, statics = project_06.assemble(f)
    assert ops == ADD_PROGRAM
    assert symbols == {}
    assert statics == {}
コード例 #6
0
def test_load_max():
    with open("examples/Max.asm") as f:
        ops, symbols, statics = project_06.assemble(f)
    assert ops == MAX_PROGRAM
    assert symbols == {"OUTPUT_FIRST": 10, "OUTPUT_D": 12, "INFINITE_LOOP": 14}
    assert statics == {}