Fix handling of indirect references

This commit is contained in:
Maurizio Porrato 2020-01-23 21:58:48 +00:00
parent 706ae9238d
commit 67904719be
1 changed files with 9 additions and 4 deletions

13
asm.py
View File

@ -46,7 +46,7 @@ class ASM(SimpleNamespace):
return (0x1f, arg) return (0x1f, arg)
elif type(arg) == Indirect: elif type(arg) == Indirect:
if type(arg.disp) == Expr: if type(arg.disp) == Expr:
disp = arg.disp.value disp = getattr(arg.disp, "value", 0)
else: else:
disp = arg.disp disp = arg.disp
if arg.reg is None: if arg.reg is None:
@ -67,10 +67,15 @@ class ASM(SimpleNamespace):
elif arg.reg in ('PC', 'EX'): elif arg.reg in ('PC', 'EX'):
raise SyntaxError() raise SyntaxError()
else: else:
if arg.disp == 0: if hasattr(type(arg.reg), "getstr"):
return (0x08+REGISTERS[arg.reg], None) r = arg.reg.getstr()
else: else:
return (0x10+REGISTERS[arg.reg], disp) r = arg.reg
print("REG: "+r)
if arg.disp == 0:
return (0x08+REGISTERS[r], None)
else:
return (0x10+REGISTERS[r], disp)
def code(self): def code(self):
o, b = OPCODES[self.op] o, b = OPCODES[self.op]
a_bits, a_extra = self.addr(self.a, True) a_bits, a_extra = self.addr(self.a, True)