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

22 lines
662 B
Python

# pylint:disable=W0622
CMDs = ["ldr", "str"]
def ldr(self, operand):
print("从内存的", operand[1], "处加载至寄存器", operand[0])
if int(operand[1]) < len(self.dtMemory):
value = self.dtMemory[int(operand[1])]
self.registers[int(operand[0])] = value
else:
print("ERROR: Attempted to load from invalid memory address.")
def str(self, operand):
# 往内存写入数据
if int(operand[1]) < len(self.dtMemory):
value = self.registers[int(operand[0])]
print(value)
self.dtMemory[int(operand[1])] = value
else:
print("ERROR: Attempted to store to invalid memory address.")