add label test

This commit is contained in:
Peter McGoron 2023-02-07 17:44:44 +00:00
parent 972a8ac8f1
commit a96bac26a8
1 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,25 @@ class ProgramTest(unittest.TestCase):
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')
def test_label(self):
p = Program()
b_ex = bytes()
p.parse_asm_line("CLB l0")
b_ex = b_ex + b'\x07\xC0\x80\x00'
p.parse_asm_line("pop r0")
b_ex = b_ex + b'\x02\xC2\x80\x00'
p.parse_asm_line("pop r1")
b_ex = b_ex + b'\x02\xC2\x81\x00'
p.parse_asm_line("mul r2 r0 r1")
b_ex = b_ex + b'\x04\xC2\x82\xC2\x80\xC2\x81\x00'
p.parse_asm_line("push r2")
b_ex = b_ex + b'\x01\xC2\x82\x00'
p.parse_asm_line("push r2")
b_ex = b_ex + b'\x01\xC2\x82\x00'
p.parse_asm_line("jl l0 r2 10")
b_ex = b_ex + b'\x06\xC0\x80\xC2\x82\xC0\x8A\x00'
b = p()
self.assertEqual(b, b_ex)
if __name__ == "__main__":
unittest.main()