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 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 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()...
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 code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a mips assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT