2024-04-29 22:03:14 +08:00
|
|
|
from error import *
|
2024-05-02 08:54:42 +08:00
|
|
|
|
2024-04-29 16:00:03 +08:00
|
|
|
CMDs = ["add", "sub", "mul", "div"]
|
|
|
|
|
2024-05-02 08:54:42 +08:00
|
|
|
|
2024-04-29 22:03:14 +08:00
|
|
|
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
|
2024-05-02 08:54:42 +08:00
|
|
|
|
|
|
|
|
2024-04-29 16:00:03 +08:00
|
|
|
def add(self, operand):
|
2024-04-29 22:03:14 +08:00
|
|
|
run = CheckArg(operand)
|
|
|
|
if run:
|
|
|
|
a = operand[0].get()
|
|
|
|
b = operand[1].get()
|
|
|
|
operand[0].set(a + b)
|
2024-05-02 08:54:42 +08:00
|
|
|
|
|
|
|
|
2024-04-29 16:00:03 +08:00
|
|
|
def sub(self, operand):
|
2024-04-29 22:03:14 +08:00
|
|
|
run = CheckArg(operand)
|
|
|
|
if run:
|
|
|
|
a = operand[0].get()
|
|
|
|
b = operand[1].get()
|
|
|
|
operand[0].set(a - b)
|
2024-05-02 08:54:42 +08:00
|
|
|
|
2024-04-29 16:00:03 +08:00
|
|
|
|
|
|
|
def mul(self, operand):
|
2024-04-29 22:03:14 +08:00
|
|
|
run = CheckArg(operand)
|
|
|
|
if run:
|
|
|
|
a = operand[0].get()
|
|
|
|
b = operand[1].get()
|
|
|
|
operand[0].set(a * b)
|
2024-05-02 08:54:42 +08:00
|
|
|
|
2024-04-29 16:00:03 +08:00
|
|
|
|
|
|
|
def div(self, operand):
|
2024-04-29 22:03:14 +08:00
|
|
|
run = CheckArg(operand)
|
|
|
|
if run:
|
|
|
|
a = operand[0].get()
|
|
|
|
b = operand[1].get()
|
|
|
|
operand[0].set(a // b)
|