Question

You are asked to implement a MIPS procedure named string_insert. The procedure will take two null-terminated ASCII strings: strl and str2 and an integer position value pos as input parameters. When

invoked, the string_insert procedure will insert a copy of str2 into str1 right before the index location indicated by pos. For example, if str1 contains the string "ABCDEFG" and str2 contains "123", then a procedure call string_insert with the pos parameter value of 5 would update str1 into "ABCDE123FG"; since the letter F had the index location of 5. If the pos value exceeds the lengths of str1, then str2 should be concatenated at the end of str1. Of the pos value equals to 0; then str2 will be prepended to str1. The string_insert procedure will not return any value. Furthermore, you also need to implement a second MIPS procedure named strlen. Like the C library function of the same name, strlen will take a string as input parameter, and return the number of characters in that string, excluding the null character. The return value of strlen will be available at the $v0 register for the caller procedure to read. You should try to implement strlen first, and then focus on string_insert because the implementation of substring_count can be greatly simplified when it can invoke the strlen procedure. The main function of the program is given in the following. You may define any additional number of helper procedures as necessary. However, the data segment as well as the body of the main function should be used exactly as given. If you need space to temporarily hold bulks of data, you can and should utilize the stack segment of the process./n.data #Static arrays used to store the two string inputs stri: .space 200 # reserve a 200-byte memory block str2: .space 200 # reserve a 200-byte memory block #String literals printstri: asciiz "Enter the first string: printstr2: .asciiz "Enter the second substring: " printstr3: .asciiz "Enter the insertion position: printstr4: .asciiz "After insertion, updated first string is: " -text .globl main main: 11, $v0, 4 #to print prompt #1 la $a0, printstri syscall li, $v0, 8 #input the first string la $a0, stri li $al, 200 syscall 11, $v0, 4 #print prompt #2 la $a0, printstr2 syscall li, $v0, 8 #input the second string la $a0, str2 li $al, 200 syscall 11, $v0, 4 #to print prompt #3 la $a0, printstr3 syscall " li, $v0, 5 #input the position value (integer) syscall #pos stored in $v0 la $a0, stri la Sal, str2 add $a2, $0, SVO jal string_insert #load the address of strl to $a0 #load the address of substri to Sal #load the position value to $a2¹ #procedure call from main/n11, $v0, 4 la $a0, printstr4 syscall la $a0, strl syscall 11, $v0, 10 syscall string_insert: #print string mode #Literal part of Output #load address of strl for output #clean exit #definition of string_insert goes below # Any additional function definition (s), including strlren To get full credit for your work, your MIPS code must be sufficiently documented with single- line comments explaining the purpose of the key parts of the program. Save your MIPS program in a single plaintext file and submit it to Moodle. Good Luck!

Fig: 1

Fig: 2

Fig: 3