You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
920 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from instruction.instruction import Instruction
from hardware.hardware import Hardware
class J(Instruction):
def instrDecode(self):
super().instrDecode()
instr = self.hw.pplReg[1][0].read()
nextPC = str(bin(Hardware.pc.read() + 4))[2:6] # PC+4再取高4位
instr_index = str(bin(instr))[8:34] # instruction转换为字符串类型时0b需要去除然后取出其中的[25:0]
self.hw.pplReg[2][0].write(nextPC)
self.hw.pplReg[2][1].write(instr_index)
def execute(self):
super().execute()
jPC = int(self.hw.pplReg[2][0].read + self.hw.pplReg[2][1].read + 2*'0') # PC <-- PC[31:28] || instr_index || 00. (||为拼接操作)
self.hw.pplReg[3][0].write(jPC)
def memAccess(self):
super().memAccess()
Hardware.pc.write(self.hw.pplReg[3][0].read())
def writeBack(self):
super().writeBack()