CPU/ASM/Jump.py

24 lines
597 B
Python
Raw Normal View History

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 = ["jmp", "jmp_if"]
def jmp(self, operand):
2024-04-29 22:03:14 +08:00
if operand[0].isImmediate():
if operand[0].get() > len(self.cmdMemory):
raise AddressError()
self.pc = operand[0].get()
else:
raise BadOperand()
2024-04-29 16:00:03 +08:00
def jmp_if(self, operand):
2024-04-29 22:03:14 +08:00
if operand[0].isImmediate():
if operand[1].isImmediate() or operand[1].isRegister():
if operand[0].get() > len(self.cmdMemory):
raise AddressError()
if operand[1].get() == 1:
self.pc = operand[0].get()
else:
raise BadOperand()