Question: can someone solve this problems usigng pyrhon and regular expressions Regex . I have the first part of the code and the files example.asm i



Implement a function to split each line (instruction or label) into separate arguments. Take a screenshot of the output and include it in your report. Using. Inst_asn list as input, split each line into separate arguments. Possible defimiters can be space, comma, parantheses. (hr Use regular expressions) Exampie: addi a1, a2, 10 changes to: ['addi', 'a1', 'a2:, '10'] def split_arg(inst_ase); enter your code here I ". end your code here 7a . - check your output by uncontenting the lines below wy Inst_ian - split__arg(inst_ann) print_asit_inst(1nst_asa) cspan stylew"background-color:Acsteb4; border: 10x solid; padding: 5px; "-Ieplenent a function to renove enpty. 1ines. Take a screenshot of the output and include it in your report,k/spans Using. 'inst, esint as input, which is now a list,, renove all of the enpty lists. def renove_enoty(instiasn): *.. enter your code here =" end your code here Wut .. check your output by uncomenting the lines below wn an Inst, asn = renove enoty(inst_asa) print_ase_tnst(inst_asm) \#\# Function to get the equivalent register's value def get_reg_value(reg_name): " gets the equivalen value for the respective register name ". reg_abi = \{"zero": , "ra": 1 , "sp": 2 , "gp": 3 , "tp": 4, , "te": 5,"t1":6, "t.": :, "se": 8, "s1": 9,"ae:10,"a1:11,"a2:12, "a3": 13,"a4:14, "a5": 15, "a6": 16," "a7": 17,"52:18,"53:19,"54n:20,"55:21,"56 ": :22,"57 ": :23, "s8": 24 , "s9": 25,"s10:26, "s11": 27,"t3:28,"t4:29, "t5" : 30,"t6":31} return int(reg.name[1:]) elif reg_name in reg_abi: return reg_abi[reg_name] elif reg_name. isdecimal(): return int(reg_name) else: raise ValueError(f"Invalid register name/value: \( \left.\{\text { reg_name }\}^{\prime \prime} ight) \) Task 8 Implement a function to replace all the register names with their equivalent valuess. Take a screenshot of the output and include it in your report. In your own words, explain the purpose of the replace_reg function. Use the function get_reg_value(), already implemented for you to replace register names with their equivalent values. def replace_reg(inst_asm): I wenter your code here In wend your code here inst_ase ; replace_reg(inst_asn) print_asm_inst(inst_asm) print("_3e) print_asm_labels(1abels)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
