more asm test

This commit is contained in:
Peter McGoron 2023-02-07 17:30:29 +00:00
parent 96e8eb95b0
commit 972a8ac8f1
2 changed files with 9 additions and 2 deletions

View File

@ -12,6 +12,12 @@ class ProgramTest(unittest.TestCase):
p.parse_asm_line("PUSH r134217727") p.parse_asm_line("PUSH r134217727")
b = p() b = p()
self.assertEqual(b, b'\x01\xFC\x87\xbf\xbf\xbf\xbf\x00') self.assertEqual(b, b'\x01\xFC\x87\xbf\xbf\xbf\xbf\x00')
def test_two(self):
p = Program()
p.parse_asm_line("PUSH r1")
p.parse_asm_line("ADD r1 5 6")
b = p()
self.assertEqual(b, b'\x01\xC2\x81\x00\x03\xC2\x81\xC0\x85\xC0\x86\x00')
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -130,10 +130,11 @@ class Line:
def __call__(self): def __call__(self):
b = bytes([self.opcode]) b = bytes([self.opcode])
for a in self.args: for a in self.args:
l = 2 if a[1] < 0x80 else None
if a[0] == ArgType.REG: if a[0] == ArgType.REG:
b = b + encode_pseudo_utf8(a[1],1,None) b = b + encode_pseudo_utf8(a[1],1,l)
else: else:
b = b + encode_pseudo_utf8(a[1],0,None) b = b + encode_pseudo_utf8(a[1],0,l)
return b + bytes([0]) return b + bytes([0])
class InstructionNotFoundException(Exception): class InstructionNotFoundException(Exception):