Question: Write a similiar code using elif that will work for sw(store word) and lw(load word) input file-open (MIPS asm.txt r) output file-open (MIPS machine code.txt,
Write a similiar code using "elif" that will work for sw(store word) and lw(load word) 
input file-open ("MIPS asm.txt" "r") output file-open ("MIPS machine code.txt", "w") for line in input file: if (line --" ") # empty lines ignored continue TT I lineline.replace (" ","") print ("Instr: ", line) line - line.replace ("","") # remove 'endline' character # show the asm instruction to screen # remove spaces anywhere in line if (line [0:4]addi'): # addi: 1-type # remove $'s anywhere line - line.replace ("$",") line = line . replace ("addi", "") line line.split (',') "addi $23, $25, 100" will be split # into three strings: "23" "25" "100" # now, line [0]-"23", line [1] if (line [2] [0]): "25", line [2] # in case imm is negative "100" line [ 2 ] line [ 2 ] . replace ( "-" , " " ) = # 2's complement conversion op = "001000" rs = format (int (line [1] ) , "05b") rt = format (int (line [0]), "05b") imm = format (int (line [2]), "016b") # make rs into 5-bit binary format # make rt 5-bit binary format # make imm into 16-bit binary format # update screen and output file print (op +""rs ""+ rt+ ""+ imm + "n" output file.write (op rs + rt + imm + " ")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
