Commit 3eb775e3 authored by Khoi Lam's avatar Khoi Lam 💬
Browse files

Properly decoded loads and stores in isa

parent 7c07ec61
......@@ -46,6 +46,13 @@ i_type_1 = {
}
}
i_type_2 = {
"NA": {
"010": "lw",
"100": "lbu",
}
}
# similar to i type, sb type doesnt have func7 and only func 3
sb_type = {
"NA": {
......@@ -101,7 +108,7 @@ def decode_type(opcode):
function that determines what type the instruction is
return type
'''
return {"0110011": "r", "0010011": "i", "0000011": "i" ,"0001111": "i1" , "1110011": "sys", "0110111": "lui", "0010111": "auipc" , "1101111": "uj", "1100011":"sb", "0100011":"s", "1100111": "jalr"}[opcode]
return {"0110011": "r", "0010011": "i", "0000011": "i" ,"0001111": "i1" , "0000011": "i2" , "1110011": "sys", "0110111": "lui", "0010111": "auipc" , "1101111": "uj", "1100011":"sb", "0100011":"s", "1100111": "jalr"}[opcode]
def decode_r_instruction(func3, func7, rd, rs1, rs2, instr_name):
......@@ -128,7 +135,7 @@ def decode_i_instruction(func3, rd, rs1, immI, instr_name):
#imm_value = str(int(imm, 2))
if rs1_name == "zero":
return "li" + " " + rd_name + " " + str(immI)
elif instr_name == "lw":
elif instr_name == "lw" or instr_name == "lbu":
return instr_name + " " + rd_name + ","+ str(immI) + "(" + rs1_name + ")"
else:
return instr_name + " " + rd_name + " " + rs1_name + " " + str(immI)
......@@ -147,7 +154,7 @@ def decode_sb_instruction(rs1, rs2, immSB, instr_name, pc):
def decode_s_instruction(rs1, rs2, immS, instr_name):
rs1_name = regNumToName(int(rs1, 2))
rs2_name = regNumToName(int(rs2, 2))
return instr_name + " LMAO"
return instr_name + " " + rs2_name + ","+ str(immS) + "(" + rs1_name + ")"
def decode_uj_instruction(immUJ, instr_name, pc):
......@@ -208,10 +215,10 @@ class Instruction():
elif self.type == "i":
if self.opcode != "0000011":
self.instr_name = i_type["NA"][self.func3]
else:
self.instr_name = "lw" # temporary fix for the fact that I types have 2 different opcodes
elif self.type == "i1":
self.instr_name = i_type_1["NA"][self.func3]
elif self.type == "i2":
self.instr_name = i_type_2["NA"][self.func3]
elif self.type == "lui":
self.instr_name = "lui"
elif self.type == "auipc":
......@@ -231,7 +238,7 @@ class Instruction():
if self.type == "r":
return decode_r_instruction(self.func3, self.func7, self.rd, self.rs1, self.rs2, self.instr_name)
elif self.type == "i" or self.type == "i1":
elif self.type == "i" or self.type == "i1" or self.type == "i2":
return decode_i_instruction(self.func3, self.rd, self.rs1, self.immI, self.instr_name)
elif self.type == "lui" or self.type == "auipc":
return decode_u_instruction(self.rd, self.immU, self.instr_name) # this is since u type only has 2 instructions : lui and auipc
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment