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.

18 lines
801 B

3 years ago
def Imm_gen(inst_code: str) -> str:
test = inst_code[25:32]
if test in ['0010011', '0000011', '1100111']: # i-Type, l, jalr
imm_out = inst_code[0:12].rjust(32, inst_code[0])
elif test == '0100011': # s
imm_out = (inst_code[0:7] + inst_code[20:25]).rjust(32, inst_code[0])
elif test == '1100011': # branch
imm_out = (inst_code[0] + inst_code[24] + inst_code[1:7] +
inst_code[20:24]).rjust(32, inst_code[0])
elif test == '1101111': # jal
imm_out = (inst_code[0] + inst_code[12:20] + inst_code[11] +
inst_code[1:11]).rjust(32, inst_code[0])
elif test in ['0110111', '0010111']: # lui, auipc
imm_out = inst_code[0:20].rjust(32, inst_code[0])
3 years ago
else:
imm_out = '0' * 32
3 years ago
return imm_out