Question

In: Computer Science

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.

Solutions

Expert Solution

Answer. Here is MISP program for the gien problem:

.data
msg1: .asciiz "Enter the string "
msg2: .asciiz "Enter the character "
count: .word 10
string: .space 100
character: .space 4
msg3: .asciiz "character  "
msg4: .asciiz "occourred in string "
msg5: .asciiz "times "

.text
.global main
main:
li $t0, 100 # end variable for loop
li $t1, 0 # start variable for loop
li $t2, 0 # to count number of occurrences

la $a0, msg1 # printing the msg1
li $v0, 4
syscall

la $a0, string # taking input string from user
li $a1, 100
  li $v0, 8
syscall

  la $a0, msg2 # printing the msg2
  li $v0, 4
syscall

  la $a0, character # taking input character from user
li $a1, 4
  li $v0, 8
syscall

  la $s0, character
lb $s1, ($s0)
  la $t3, string
lb $a2, ($t3)
syscall

loop:
beq $a2, $zero,end # printing the result, if reached end of the array
beq $a2, $s1, something   
addi $t3, $t3, 1 # incrementing char array
lb $a2, ($t3)
j loop

something:
addi $t2, $t1, 1 # incrementing number of occurences of character

end:
la $a0, msg3
li $v0, 4
syscall

  la $a0, character
li $v0, 11
syscall

  la $a0, msg4
li $v0, 4
syscall

  la $a0, string
li $v0, 4
​​​​​​​ syscall

li $v0, 1
move $a0, $t2
​​​​​​​ syscall

  la $a0, msg5
li $v0, 4
​​​​​​​ syscall


Related Solutions

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).
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). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
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.
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
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...
Write a program that prompts the user for their first and lastname. Display the first...
Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.Ask the user to input a phone number.The program checks which part of Colorado a phone number is from using the values below.If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits...
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT