예제 #1
0
def test_multiple_lines():
    parse("""
; infinite loop
label:
always.jump label
    """)
    assert True
예제 #2
0
def test_multiple_lines2():
    parse("""
link sub
halt

sub:
jump
    """)
    assert True
예제 #3
0
        exit(1)


    if len(sys.argv) < 3:
        print ("FILE argument is missing")
        exit(2)

    if sys.argv[1] in ('run', 'load', 'disasm'):
        wc = load_hex(m, sys.argv[2])

    if sys.argv[1] == 'run':
        m.run()
        exit(0)

    if sys.argv[1] == 'asm':
        tokens = parse(open(sys.argv[2]).readlines())
        for token in tokens:
            print ('%04x' % token.asm(), end='')
        print ('')
        exit(0)

    if sys.argv[1] == 'disasm':
        while m.PC.get() < wc:
            try:
                # TODO: make this optional
                # print ("%04x: " % m.PC.get(), end='')
                w = m._fetch()
                insn = m._decode(w)
                print (insn)

            except InvalidInstruction:
예제 #4
0
def test_complete_line():
    res = parse("jump: always.jump jump ; jump")
    assert str(res[0]) == "Label: jump"
    assert str(res[1]) == "Instruction: always.jump jump"
예제 #5
0
def test_empty():
    parse("")
    assert True
예제 #6
0
def test_operand_hexadecimal():
    res = parse("jump deadbeefh")
    assert str(res[0]) == "Instruction: always.jump 3735928559"
예제 #7
0
def test_comment():
    res = parse("; foo")
    assert str(res[0]) == "Comment: foo"
예제 #8
0
def test_operand_octal():
    res = parse("jump 0770o")
    assert str(res[0]) == "Instruction: always.jump 504"
예제 #9
0
def test_operand_decimal():
    res = parse("jump -9999d")
    assert str(res[0]) == "Instruction: always.jump -9999"
예제 #10
0
def test_operand_binary():
    res = parse("jump 0101_0110b")
    assert str(res[0]) == "Instruction: always.jump 86"
예제 #11
0
def test_operand_label():
    res = parse("jump foo")
    assert str(res[0]) == "Instruction: always.jump foo"
예제 #12
0
def test_condition():
    res = parse("safe.halt")
    assert str(res[0]) == "Instruction: safe.halt"
예제 #13
0
def test_mnemonic():
    res = parse("halt")
    assert str(res[0]) == "Instruction: always.halt"
예제 #14
0
def test_label():
    res = parse("foo:")
    assert str(res[0]) == "Label: foo"