CPU/ASM/Logical.py

30 lines
630 B
Python
Raw Permalink Normal View History

2024-05-02 08:54:42 +08:00
CMDs = ["eq", "halt"] # , 'en', 'gt', 'lt', 'ge', 'le']
2024-04-29 16:00:03 +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-04-29 16:00:03 +08:00
2024-05-02 08:54:42 +08:00
2024-04-29 16:00:03 +08:00
def eq(self, operand):
2024-04-29 22:03:14 +08:00
if CheckArg(operand) and operand[2].isRegister():
# 是否等于
a = operand[0].get()
b = operand[1].get
if a == b:
operand[2].set(1)
else:
operand[2].set(0)
2024-05-02 08:54:42 +08:00
2024-04-29 22:03:14 +08:00
def halt(self, operand):
2024-05-02 08:54:42 +08:00
return False