Properly handle non-instruction bytes in the range 0xa0…0xbf

Previously address arguments were extracted without verifying the start
byte corresponded to a valid instruction. In case of a non-instruction
byte this would result in the two following bytes to be silently
skipped.
This commit is contained in:
Juhani Krekelä 2022-05-10 11:19:22 +02:00
parent 57473ee34e
commit 66e28d6ef8
2 changed files with 10 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.bin

View File

@ -41,23 +41,22 @@ def segment(binary, origin):
rx = (byte >> 2) & 3
ry = byte & 3
addr = None
if opcodes[opcode].addr:
addr = (binary[ip + 1] << 8) + binary[ip + 2]
valid = True
if not opcodes[opcode].rx and rx != 0: valid = False
if not opcodes[opcode].ry and ry != 0: valid = False
if valid:
if not valid:
statements.append(Statement(ip, Data(byte)))
ip += 1
elif opcodes[opcode].addr:
addr = (binary[ip + 1] << 8) + binary[ip + 2]
instruction = Instruction(opcode, rx, ry, addr)
statements.append(Statement(ip, instruction))
ip += 3
else:
statements.append(Statement(ip, Data(byte)))
ip += 1
if opcodes[opcode].addr:
ip += 2
instruction = Instruction(opcode, rx, ry, None)
statements.append(Statement(ip, instruction))
ip += 1
return statements