In: Statistics and Probability
MIPS ASSEMBLY
Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample runs). In order to work with characters, we need to remember that each ASCII character is stored using a single byte. So, we will now add in the instructions load byte (lb) and store byte (sb) in order to manipulate our character information.
Requirements:
● While you can set how long the string can be at maximum, you can’t tell the user a specific length that the string must be (e.g. Enter a string of length 10) and you can’t ask them how long the string is.
● After you have their string, you will prompt them to see if they want to make any changes. If they do, then read in the character that they want to change in the string and then the character that they want to change it to. o All characters of the same type in the string can be affected, not just a single one of them. So, if they choose to change the spaces to dashes, all spaces are affected. (See sample run 2)
● After each change print the current string out to them and ask if they want to make another change.
● When they are finished making changes, print the final string and then exit the program properly.
Sample Output: (The prompt: followed by the output)
This program reads in a String from the user and then allows the user to make changes to it until they want to stop.
Please enter your string now (maximum of 40 characters): We can input a fairly long string.
Your current string is: We can input a fairly long string.
Do you want to make any changes to the string? (Y/N): Y
Enter the character in the string would you like replaced: i
Enter what you would like to change the character to: 1
Your current string is:
We can 1nput a fa1rly long str1ng.
Do you want to make any changes to the string? (Y/N): Y
Enter the character in the string would you like replaced: a
Enter what you would like to change the character to: @
Your current string is: We c@n 1nput @ f@1rly long str1ng.
Do you want to make any changes to the string? (Y/N): N
Your final string is: We c@n 1nput @ f@1rly long str1ng.
-- program is finished running –
This program reads in a String from the user and then allows the user to make changes to it until they want to stop.
Please enter your string now (maximum of 40 characters): A short one too.
Your current string is: A short one too.
Do you want to make any changes to the string? (Y/N): Y
Enter the character in the string would you like replaced: Enter what you would like to change the character to: =
Your current string is: A-short-one-too.
Do you want to make any changes to the string? (Y/N): N
Your final string is: A-short-one-too.
-- program is finished running --
This program reads in a String from the user and then allows the user to make changes to it until they want to stop.
Please enter your string now (maximum of 40 characters): We could change nothing.
Your current string is: We could change nothing.
Do you want to make any changes to the string? (Y/N): N
Your final string is: We could change nothing.
- - programs finished running - -
Sol:
Screenshot

Program
######################################################################################
   #Program to read a string
   #Get replace character
   #change that into given new charcter
   #Display string each time
######################################################################################
.data
   #Input prompt for string
   prompt1: .asciiz "Please enter your string now
(maximum of 40 characters): "
   #Input prompt for charcter to change
   prompt2: .asciiz "\nEnter the character in the string
would you like replaced: "
   #Input prompt for change charcter
   prompt3: .asciiz "\nEnter what you would like to
change the character to: "
   #Input prompt for repetition
   prompt4: .asciiz "Do you want to make any changes to
the string? (Y/N): "
   #Output message
   output1: .asciiz "Your current string is: "
   #Space for string storage
   str: .space 40
#Program starts here
.globl main
.text
main:
   #Prompt for input string
   la $a0,prompt1
   li $v0,4
   syscall
   #Read string
   la $a0,str
   li $a1,40
   li $v0,8
   syscall
top:
   #Display string message
   la $a0,output1
   li $v0,4
   syscall
   #Display string
   la $a0,str
   li $v0,4
   syscall
   #Prompt for change
   la $a0,prompt4
   li $v0,4
   syscall
   li $v0,12
   syscall
   #Check for 'N'
   beq $v0,78,end
   #Prompt for change charcter
   la $a0,prompt2
   li $v0,4
   syscall
   #Read character
   li $v0,12
   syscall
   #Save in a1
   move $a1,$v0
   #Prompt for change charcter
   la $a0,prompt3
   li $v0,4
   syscall
   #Read character
   li $v0,12
   syscall
   #Save in a2
   move $a2,$v0
   la $a0,str
   #Call function
   jal change
   #Next line
   li $a0,10
   li $v0,11
   syscall
   #Go to top
   j top
end:
   #Next line
   li $a0,10
   li $v0,11
   syscall
   #Display string message
   la $a0,output1
   li $v0,4
   syscall
   #Display string
   la $a0,str
   li $v0,4
   syscall
   #End of the program
   li $v0,10
   syscall
#Function to implement change
change:
#Get each character
   lb $t0,($a0)
   #String end check
   beq $t0,0,ret
   #Check for match letter
   bne $t0,$a1,nextVal
   #Replace
   sb $a2,($a0)
#Get enxt character
nextVal:
   addi $a0,$a0,1
   j change
#Return to main
ret:
jr $ra
output
Please enter your string now (maximum of 40 characters): We can
input a fairly long string.
Your current string is: We can input a fairly long string.
Do you want to make any changes to the string? (Y/N): Y
Enter the character in the string would you like replaced: i
Enter what you would like to change the character to: 1
Your current string is: We can 1nput a fa1rly long str1ng.
Do you want to make any changes to the string? (Y/N): Y
Enter the character in the string would you like replaced: a
Enter what you would like to change the character to: @
Your current string is: We c@n 1nput @ f@1rly long str1ng.
Do you want to make any changes to the string? (Y/N): N
Your current string is: We c@n 1nput @ f@1rly long str1ng.
-- program is finished running --