21 lines
518 B
Python
21 lines
518 B
Python
CMDs = ["add", "sub", "mul", "div"]
|
|
|
|
|
|
def add(self, operand):
|
|
self.registers[int(operand[0])] += self.registers[int(operand[1])]
|
|
|
|
|
|
def sub(self, operand):
|
|
self.registers[int(operand[0])] -= self.registers[int(operand[1])]
|
|
|
|
|
|
def mul(self, operand):
|
|
self.registers[int(operand[0])] *= self.registers[int(operand[1])]
|
|
|
|
|
|
def div(self, operand):
|
|
if self.registers[int(operand[1])] != 0:
|
|
self.registers[int(operand[0])] //= self.registers[int(operand[1])]
|
|
else:
|
|
raise ZeroDivisionError()
|