Question

In: Computer Science

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.

Solutions

Expert Solution

.data 
    command1:   .asciiz "Please enter a sentence "
    command2:   .asciiz "Please enter a character "
    count:      .word 10
    sentence:   .space 100
    character:  .space 4
    command3:   .asciiz " Character "
    command4:   .asciiz " appears in the sentence "
    command5:   .asciiz " times. "

.text
.globl main
main:
    li $t0, 100 #end var for loop
    li $t1, 0   #start var for loop
    li $t2, 0   #number of occurences

    la $a0, command1    #print 'please enter sentence'
    li $v0, 4
    syscall


    la $a0, sentence    #input sentence
    li $a1, 100
    li $v0, 8
    syscall

    la $a0, command2    #print 'please enter char'
    li $v0, 4
    syscall

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

    la $s0, character
    lb $s1, ($s0)
    la $t3, sentence
    lb $a2, ($t3) #gets first char of string

loop:
    beq $a2, $zero, end     #once reach end of char array, prints result
    beq $a2, $s1, something #if the char within sentence == comparing char
    addi $t3, $t3, 1
    lb $a2,($t3)        
    j loop

something:              
    addi $t2, $t2, 1        #increments number of occurences of char 
end:
    la $a0, command3
    li $v0, 4
    syscall

    la $a0, character
    li $v0, 11
    syscall

    la $a0, command4
    li $v0, 4
    syscall

    la $a0 sentence
    li $v0, 4
    syscall

    #la $a0, $t2
    li $v0, 1
    move $a0, $t2
    syscall

    la $a0, command5
    li $v0, 4
    syscall

Hope this helps you. Please give an upvote. Thank you.


Related Solutions

Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
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.
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
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 mips program that would function in QTSPIM that asks the user to enter a...
Write a mips program that would function in QTSPIM that asks the user to enter a list of integer values, one per line, with the last value being a negative. The program should read in these integers until a negative number is entered. Afterwards the program should print 1) sum, 2) minimum value, 3) max value, 4) mean and 5) variance value. of the numbers that were entered.
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
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 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 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
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string. Prints out four different versions of that string: The original version of the string. The upper-case version of the string. The lower-case version of the string. A version where the character at position 0 capitalized, and all other characters in lower case. For example: if the user enters string "gaNDalF12 !! AB3w", your program output should look EXACTLY like this: Please enter a string:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT