Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help Please !!!!!!!! **Python with regex expresion * using and assambly code file I have beed post it many time , do not copy from

Help Please !!!!!!!!
**Python with regex expresion * using and assambly code file
I have beed post it many time , do not copy from other answers because this are incorrect !!!!!
I need help with this problems to impoement it in python and using regular expression Regex .
Description !!!!
image text in transcribed
Inicial Code
image text in transcribed
image text in transcribed
image text in transcribed
File with the Assambly code example.asm
image text in transcribed
Question that I need to anwsers
image text in transcribed
image text in transcribed
image text in transcribed
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 \#\# \#\# 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): " 'prints list of labels". print("Assembly Labels:") if len(labels) ==0 : print(None) else: max_len =max(5,max([ len ( label ) for label in labels] )) print (f'f'LABEL':}} | {VALUE:>5} ) for label, val in labels.items(): print(f"\{label:}}{val:>5}) 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 o (rows) corresponds \#\# to each line in the file and axis 1 (columns) corresponds to each argument in that instruction filename = "input.asm" inst_asm = read(filename) print_asm_inst(inst_asm) \# Implement a RISC-V program to multiply two numbers using loop adder main: "beq a1, zero, done \# if the second operand is equal to , then goto done loop: waddi a1, a1, 1 wne a1, zero loop done: Implement a function to split each line (instruction or label) into separate arguments. Take a screenshot of the output and incluc it in your report. 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'] def split_arg(inst_asm): n .. enter your code here w ... end your code here \#\#N .. check your output by uncomenting the lines below . NIf inst_asm = split_arg(inst_asm) print_asm_inst(inst_asm) Implement a function to remove empty lines. Take a screenshot of the output and include it in your report. Using inst_asm as input, which is now a list, remove all of the empty lists. def remove_empty(inst_asm): \# ... enter your code here. \#... end your code here \#\# -. check your output by uncommenting the lines below .. \#\# inst_asm = remove_empty(inst_asm) print_asm_inst(inst_asm) 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): "... enter your code here \# .. end your code here \#A . check your output by uncommenting the lines below .. \#A A inst_osm = replace_reg(inst_asm) \# print_asm_inst(inst_asm) \# print (3) \# print_asm_Labets(labets)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

ISBN: 3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

Cash dividends are not expenses. Explain.

Answered: 1 week ago