def generate_jr(fields): # Chequear que no de error porque fields es una sola palabra opcode = "000000" rs = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) return str(opcode + rs + "000000000000000001000")
def rd_rs_shamt(fields): rs = dec_to_binary.strdec_to_bin(int((fields[1])[1:-1]), 5) rd = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) shamt = dec_to_binary.strdec_to_bin(int((fields[2])[:-1]), 5) return str(rs + "00000" + rd + shamt)
def rt_offset_base(fields): base = dec_to_binary.strdec_to_bin(int((fields[1].split("($")[1])[:-2]), 5) rt = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) offset = dec_to_binary.strdec_to_bin(int(fields[1].split("($")[0]), 16) return str(base + rt + offset)
def rt_immediate(fields): rt = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) immediate = dec_to_binary.strdec_to_bin(int((fields[1])[:-1]), 16) return str(rt + immediate)
def rs_rt_offset(fields): rs = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) rt = dec_to_binary.strdec_to_bin(int((fields[1])[1:-1]), 5) offset = dec_to_binary.strdec_to_bin(int((fields[2])[:-1]), 16) return str(rs + rt + offset)
def rd_rs_rt(fields): rs = dec_to_binary.strdec_to_bin(int((fields[1])[1:-1]), 5) rt = dec_to_binary.strdec_to_bin(int((fields[2])[1:-1]), 5) rd = dec_to_binary.strdec_to_bin(int((fields[0])[1:-1]), 5) return str(rs + rt + rd)
def generate_jal(fields): # Chequear que no de error porque fields es una sola palabra opcode = "000011" target = dec_to_binary.strdec_to_bin(int((fields[0])[:-1]), 26) return str(opcode + target)