fixed some bugs in the assembler

This commit is contained in:
2018-10-09 15:55:42 +02:00
parent c5bc1c92d1
commit f7cb729e4d
4 changed files with 112 additions and 23 deletions

View File

@@ -52,3 +52,20 @@ def test_tokenize_3():
, "string", ":", "\n"
, ".", "set", " ", "[", "'h'", ",", "'e'", ",", "'l'", ",", "'l'", ",", "'o'", "]", "\n"
]
def test_tokenize_4():
data = '''
ldi r0, 0xfefe
test_mark:
ldi r1, 0xefef
'''
data = StringIO(data)
tokenizer = Tokenizer(FileContext(data))
result = list(tokenizer)
assert result == [
"ldi", " ", "r0", ",", "0xfefe", "\n"
, "test_mark", ":", "\n"
, "ldi", " ", "r1", ",", "0xefef", "\n"
]

View File

@@ -17,6 +17,52 @@ def test_commands(basic_machine_definition):
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
assert assembler._code_objects == [32704, 0, 0xfe
, 32704, 1, 0xfe
, 40896, 0, 1]
assert assembler._code_objects == [32704 | 0, 0xfe
, 32704 | 1, 0xfe
, 40896 | 0, 1]
def test_mark(basic_machine_definition):
memory_definition, command_defintion = basic_machine_definition
data = StringIO(
'''
ldi r0, test_mark
ldi r1, 0xfe
test_mark:
add r0, r1
'''
)
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
assert assembler._code_objects == [32704 | 0, 4
, 32704 | 1, 0xfe
, 40896 | 0, 1]
def test_set_directive(basic_machine_definition):
memory_definition, command_defintion = basic_machine_definition
data = StringIO(
'''
ldi r0, test_mark
ldi r1, 0xfe
test_mark:
.set [0xfe, 0xef,
10, 20,
'a', 'b',
'\\n', 0b10]
'''
)
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
assert assembler._code_objects == [32704 | 0, 4
, 32704 | 1, 0xfe
, 0xfe, 0xef
, 10, 20
, ord("a"), ord("b")
, ord("\n"), 0b10]