Question

In: Statistics and Probability

MIPS ASSEMBLY Have the user input a string and then be able to make changes to...

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 - -

Solutions

Expert Solution

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 --


Related Solutions

Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Write an assembly language program to input a string from the user. Your program should do...
Write an assembly language program to input a string from the user. Your program should do these two things: ***** I AM POSTING THIS QUESTION FOR THE THIRD TIME NOW,I WANT IT DONE USING INCLUDE IRVINE32.INC***** 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be:...
in MIPS assembly, ask a user for two numbers and to either enter a '1' for...
in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').
Create a class that calls for user to input a string. Pass the string from that...
Create a class that calls for user to input a string. Pass the string from that class to another and count how many words the string has, count how many vowels are in the string and count how many letters end with d. java language
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT