CPU/ASM/count.py
2024-04-29 16:01:52 +08:00

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()