aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-07 17:30:29 +0000
committerGravatar Peter McGoron 2023-02-07 17:30:29 +0000
commit972a8ac8f107d8529ed2cccf62e672ef965bb5ed (patch)
tree89ebf597f969ea458d843127733049403322278f
parentassembler: refactor and start tests (diff)
more asm test
-rw-r--r--asm_test.py6
-rw-r--r--creole_asm.py5
2 files changed, 9 insertions, 2 deletions
diff --git a/asm_test.py b/asm_test.py
index 481875b..016f634 100644
--- a/asm_test.py
+++ b/asm_test.py
@@ -12,6 +12,12 @@ class ProgramTest(unittest.TestCase):
p.parse_asm_line("PUSH r134217727")
b = p()
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__":
unittest.main()
diff --git a/creole_asm.py b/creole_asm.py
index 8f7ab22..8e87b58 100644
--- a/creole_asm.py
+++ b/creole_asm.py
@@ -130,10 +130,11 @@ class Line:
def __call__(self):
b = bytes([self.opcode])
for a in self.args:
+ l = 2 if a[1] < 0x80 else None
if a[0] == ArgType.REG:
- b = b + encode_pseudo_utf8(a[1],1,None)
+ b = b + encode_pseudo_utf8(a[1],1,l)
else:
- b = b + encode_pseudo_utf8(a[1],0,None)
+ b = b + encode_pseudo_utf8(a[1],0,l)
return b + bytes([0])
class InstructionNotFoundException(Exception):