示例#1
0
def test_ld_byte():
    asm = """
        LD V0, #12
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == int("12", 16)
示例#2
0
def test_shr():
    asm = """
        LD V0, #2
        SHR V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 1
示例#3
0
def test_shl():
    asm = """
        LD V0, #1
        SHL V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 2
示例#4
0
def test_add_byte():
    asm = """
        LD V0, #1
        ADD V0, #1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 2
示例#5
0
def test_rnd_v0_is_zero():
    asm = """
        LD V0, #0
        RND V0, #0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 0
示例#6
0
def test_rnd():
    asm = """
        LD V0, #0
        RND V0, #f
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") != 0
示例#7
0
def test_se_byte():
    asm = """
        LD V0, #1
        SE V0, #1
        LD V0, #2
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 1
示例#8
0
def test_shl_with_first_bit_one():
    asm = """
        LD V0, #80
        SHL V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 0
    assert emulator_debug.get("VF") == 1
示例#9
0
def test_or():
    asm = """
        LD V0, #1
        LD V1, #3
        OR V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 3
示例#10
0
def test_call():
    asm = """
        CALL test
        EXIT

test:   EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("PC") == 0x200 + 6
示例#11
0
def test_ld_register():
    asm = """
        LD V0, #1
        LD V1, #2
        LD V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == int("2", 16)
示例#12
0
def test_shr_with_last_bit_one():
    asm = """
        LD V0, #3
        SHR V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 1
    assert emulator_debug.get("VF") == 1
示例#13
0
def test_sub_register():
    asm = """
        LD V0, #1
        LD V1, #1
        SUB V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 0
示例#14
0
def test_subn_not_borrow():
    asm = """
        LD V0, #1
        LD V1, #2
        SUBN V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 1
    assert emulator_debug.get("VF") == 1
示例#15
0
def test_add_register_with_carry():
    asm = """
        LD V0, #1
        LD V1, #FF
        ADD V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 0
    assert emulator_debug.get("VF") == 1
示例#16
0
def test_sub_register_with_carry():
    asm = """
        LD V0, #f
        LD V1, #1
        SUB V0, V1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 14
    assert emulator_debug.get("VF") == 1
示例#17
0
def test_se_register():
    asm = """
        LD V0, #1
        LD V1, #1
        LD V3, #1
        SE V0, V1
        LD V3, #2
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V3") == 1
示例#18
0
def test_jp():
    asm = """
        LD V0, #1
        JP test
        EXIT
test:   LD V0, #2
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 2
    assert emulator_debug.get("PC") == 0x200 + 8
示例#19
0
def test_jp_with_v0():
    # hex #204 + #2 is the EXIT row
    asm = """
        LD V0, #2
        JP V0, #204
        LD V0, #1
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 2
    assert emulator_debug.get("PC") == 0x200 + 6