Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i Need this in python using Regex Expresion description first part of the code i need this Task example.asm file Lab 03 - ISA Assembler
i Need this in python using Regex Expresion
Lab 03 - ISA Assembler Design (Part 1) In this lab, you will be desgning an assembler to pre-process an assembly code. TODO - Pre-process assembly code ('example.asm') by completing Tasks 1 - 8 - Save the pre-processed code to a 'txt' file (Task 9) Some portions of the code have already been implemented for you such as reading the assembly code file, converting the register names to their equivalent values and printing the processed instructions and labels. Also, assume that inputs for a task are outputs from the previous task. \#\# Function to read the assembly code file \#\# def read(filename): "'read each line from a file'. asm_inst = list() with open(filename, ' r ') as f : for line in f : asm_inst, append(line) return asm_inst \#\# Function to get the equivalent register's value def get_reg_value(reg_name): "gets the equivalen value for the respective register name" 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: \( \{\text { reg_name }\}^{\prime \prime} \) ) \#\# FOR TESTING: Function to print the instructions def print_asm_inst(inst_asm): "'prints list of instructions" " print("Assembly Instructions:") if len(inst_asm) ==0: print(None) else: for line in inst_asm: print(line) \#\# \#\# FOR TESTING: Function to print the labels def print_asm_labels(labels): inst_asm = [] \# List to store instructions labels =[] list to store Labels \#\# reads assembly code and stores it in list of lists 'inst_asm' where axis (rows) corresponds \#\# to each line in the file and axis 1 (columns) corresponds to each argument in that instruction filename = "example. asm" " inst_asm = read(filename) print_asm_inst(inst_asm) Using inst_asm list as input, split each line into separate arguments. Possible delimiters can be space, comma, parantheses. (Hint: Use regular expressions) Example: addi a1, a2, 10 changes to: ['addi', 'a1', 'a2', '10'] HA "Task 3** cspan style="background-color:\#CSEB4; border: 1px solid; padding: 5px; ">Implement a function to remove empty lines. Take a screenshot of the output and include it in your report. / spans Using 'inst_asm' as input, which is now a list, renove all of the empty lists description
first part of the code
i need this Task
example.asm file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started