from error import * CMDs = ["add", "sub", "mul", "div"] def CheckArg(operand): run = False if operand[0].isRegister(): if operand[1].isRegister(): run = True elif operand[0].isRegister(): if operand[1].isImmediate(): run = True else: raise BadOperand() return run def add(self, operand): run = CheckArg(operand) if run: a = operand[0].get() b = operand[1].get() operand[0].set(a + b) def sub(self, operand): run = CheckArg(operand) if run: a = operand[0].get() b = operand[1].get() operand[0].set(a - b) def mul(self, operand): run = CheckArg(operand) if run: a = operand[0].get() b = operand[1].get() operand[0].set(a * b) def div(self, operand): run = CheckArg(operand) if run: a = operand[0].get() b = operand[1].get() operand[0].set(a // b)