from io import StringIO import pytest from assembler.assembler import Assembler def test_commands(basic_machine_definition): memory_definition, command_defintion = basic_machine_definition data = StringIO( ''' ldi r0, 0xfe ldi r1, 0xfe add r0, r1 ''' ) assembler = Assembler(data, memory_definition, command_defintion, {}) assembler.parse() 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]