示例#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"