Esempio n. 1
0
def test_ld_byte():
    asm = """
        LD V0, #12
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == int("12", 16)
Esempio n. 2
0
def test_shr():
    asm = """
        LD V0, #2
        SHR V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 1
Esempio n. 3
0
def test_shl():
    asm = """
        LD V0, #1
        SHL V0
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") == 2
Esempio n. 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
Esempio n. 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
Esempio n. 6
0
def test_rnd():
    asm = """
        LD V0, #0
        RND V0, #f
        EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("V0") != 0
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 10
0
def test_call():
    asm = """
        CALL test
        EXIT

test:   EXIT
    """
    emulator_debug = run_asm(asm)
    assert emulator_debug.get("PC") == 0x200 + 6
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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