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.
53 lines
2.1 KiB
53 lines
2.1 KiB
class Tomasulo:
|
|
def __init__(self, asm_file):
|
|
lines = []
|
|
self.instructions = []
|
|
self.clock = 0
|
|
self.load_buffer = [{"busy": "no", "address": ""}, {"busy": "no", "address": ""}, {"busy": "no", "address": ""}]
|
|
with open(asm_file) as f:
|
|
lines = f.readlines()
|
|
for i in range(len(lines)):
|
|
self.instructions.append(self.parse_instruction(lines[i]))
|
|
|
|
def parse_instruction(self, line):
|
|
line = line.lower()
|
|
instruction = {}
|
|
elements = line.replace(",", " ").replace("(", " ").replace(")", " ").replace("\n", "").split(" ")
|
|
if ":" in elements[0]:
|
|
instruction["label"] = elements[0].split(":")[0]
|
|
instruction["opcode"] = elements[1]
|
|
del elements[0]
|
|
else:
|
|
instruction["opcode"] = elements[0]
|
|
if instruction["opcode"] == "l.d":
|
|
instruction["rd"] = elements[1]
|
|
instruction["rs1"] = elements[3]
|
|
instruction["imm"] = elements[2]
|
|
elif instruction["opcode"] == "mul.d":
|
|
instruction["rd"] = elements[1]
|
|
instruction["rs1"] = elements[2]
|
|
instruction["rs2"] = elements[3]
|
|
elif instruction["opcode"] == "s.d":
|
|
instruction["rd"] = elements[3]
|
|
instruction["rs1"] = elements[2]
|
|
instruction["imm"] = elements[1]
|
|
elif instruction["opcode"] == "daddui":
|
|
instruction["rd"] = elements[1]
|
|
instruction["rs1"] = elements[2]
|
|
instruction["imm"] = elements[3].replace("#", "")
|
|
elif instruction["opcode"] == "bne":
|
|
instruction["rs1"] = elements[1]
|
|
instruction["rs2"] = elements[2]
|
|
instruction["imm"] = elements[3]
|
|
instruction["issue"] = 0
|
|
instruction["exec comp"] = 0
|
|
instruction["write result"] = 0
|
|
return instruction
|
|
|
|
def run(self):
|
|
self.clock += 1
|
|
|
|
def print_instructions(self):
|
|
for i in range(len(self.instructions)):
|
|
print(self.instructions[i])
|