Write a MIPS assembly language program that prompts the user to input two string
ID: 3757157 • Letter: W
Question
Write a MIPS assembly language program that prompts the user to input two strings (each should be no longer than 50 characters including the null terminator). Your program should determine whether the second string is a substring of the first. If it is, then your program should print out the first index in which the second string appears in the first. For example, if the first string is “Hello World” and the second string is “lo”, then the program should print out 3, i.e. the starting index of “lo” in “Hello World.” If the second string is not contained in the first string, then your program should print out -1.
Explanation / Answer
Here is the clear solution for your problem
.data
out_str: .asciiz "Enter the String Max of size 50 "
out_int: .asciiz "Enter the Integer index "
userInput_str: .space 50
.text
main :
#1. Taking string as input from user and store it in userInput_str
li $v0, 4
la $a0, out_str #load Address
syscall
li $v0, 8
la $a0, userInput_str
li $a1, 50
syscall
#Taking integer index as input from user
li $v0, 4
la $a0, out_int #load Address
syscall
li $v0, 5
syscall
move $t0, $v0
#Display Name
la $a1,userInput_str
addu $a1,$a1,$t0
li $v0,4
la $a0, 0($a1)
syscall # and print it
#end of program
li $v0,10
syscall
exit:
Thanks
Thumbs Up If you like it
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.