diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 2ffabcd..11d2e9e 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -556,9 +556,11 @@ class Compiler(object): if instr.direction > 0: self.compile_inc(instr, instr.dest) + final = instr.final.succ() elif instr.direction < 0: self.compile_dec(instr, instr.dest) - self.compile_cmp(instr, instr.final, instr.dest) + final = instr.final.pred() + self.compile_cmp(instr, final, instr.dest) self.emitter.emit(BNE(Relative(top_label))) def compile_with_interrupts_off(self, instr): diff --git a/src/sixtypical/model.py b/src/sixtypical/model.py index 75f7a7f..30d5d54 100644 --- a/src/sixtypical/model.py +++ b/src/sixtypical/model.py @@ -296,6 +296,20 @@ class ConstantRef(Ref): def low_byte(self): return self.value & 255 + def pred(self): + assert self.type == TYPE_BYTE + value = self.value - 1 + while value < 0: + value += 256 + return ConstantRef(self.type, value) + + def succ(self): + assert self.type == TYPE_BYTE + value = self.value + 1 + while value > 255: + value -= 256 + return ConstantRef(self.type, value) + REG_A = LocationRef(TYPE_BYTE, 'a') REG_X = LocationRef(TYPE_BYTE, 'x')