diff --git a/04_semantics_and_running/main.py b/04_semantics_and_running/main.py index e218a0e..4765d51 100644 --- a/04_semantics_and_running/main.py +++ b/04_semantics_and_running/main.py @@ -420,6 +420,9 @@ class CompileData: if instructions[i].opcode not in ['addq', 'subq']: i += 1 continue + if instructions[i].operands[1][0] != '$' or instructions[i + 1].operands[1][0] != '$': + i += 1 + continue if instructions[i].operands[1] != instructions[i + 1].operands[1]: i += 1 continue @@ -428,6 +431,9 @@ class CompileData: rhs = int(instructions[i + 1].operands[0][1:]) if instructions[i + 1].opcode == 'subq': rhs = -rhs new_value = lhs + rhs + if abs(new_value) > 0xFFFFFFFF: + i += 1 + continue new_opcode = 'addq' if new_value >= 0 else 'subq' instructions[i] = Instruction(new_opcode, [f'${abs(new_value)}', instructions[i].operands[1]]) instructions.pop(i + 1)