Question

Prompt the user and read in a string. Make your string large enough to hold 100...

Prompt the user and read in a string. Make your string large enough to hold 100 characters.

2. Count the number of words in the string. A word is one or more non-blank characters separated by one or more blanks. My suggestion is to use a flag (a boolean variable) to indicate whether or not you are in a word. Then you know you have found a word when the flag indicates that you are in a word and the next character is a blank. Think about how you will know when you have found the end of a word, and what you should do with your flag at that point.

3. Create a new string which is a copy of the original string, except that the new string is converted to uppercase. All non-letter characters should be unchanged. Convert the letters using difference between the ASCII codes for capital letters and the ASCII codes for small letters. Do not create nested if processing.

4. Print the original string, the new string, and the word count. Make sure you print messages to label your output.

When we call syscall to read in a string, we give a length n in $a1. syscall reads in at most n-1 characters and it adds a null byte (which has the value Oxo) to the end of the string. If the string is less than n-1 characters, then syscall adds a newline (which has the value Oxa) after the null byte. This means that the last word can end with either a blank, the null byte, or a newline. However, since the newline is always followed by the null byte, you can ignore the newline. But you will need to look for the null byte since there may not be a blank after the last

Written in MIPS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

#Data declaration part .data prompt: .asciiz Enter a string: wordsCount: .asciiz Words count = upperCase: .asciiz nSt

Program

#Data declaration part
.data
    prompt: .asciiz "Enter a string: "
    wordsCount: .asciiz "Words' count = "
    upperCase: .asciiz "\nString after uppercasing = "
    string: .byte 100
  
#Program starts her
.text
    #Prompt for string
    addi $v0,$0,4
    la $a0,prompt
    syscall
    #Read string
    li $v0,8
    la $a0,string
    addi $a1,$0,100
    syscall
    #Copy of the string
    add $s0,$0,$a0
    #Call function to count words
    jal WordCount
    #Store word count in t0 temporarly
    add $t0,$v0,$0
    #Display wor count message
    addi $v0,$0,4
    la $a0,wordsCount
    syscall
    #Display count
    addi $v0,$0,1
    add $a0,$0,$t0
    syscall
    #For uppercase function argument pass
    add $a0,$0,$s0
    #Call function to change uppercase
    jal Uppercase
    #Display message
    addi $v0,$0,4
    la $a0,upperCase
    syscall
    #Display sttring
    add $a0,$s0,$0
    addi $v0,$0,4
    syscall
    #end of the program
    addi $v0,$0,10
    syscall
#Implement a function to count number of words
WordCount:
    #Word count storung variable
    addi $v0,$0,0
    #Variable act as flag
    addi $t1,$0,0
#Loop until reach end of the string
Loop:
    #Get each charecters
    lb $t0,0($a0)
    #Check end of the line
    beq $t0,10,ret
    #Check space
    beq $t0,32,space
    #After space increment
    beq $t1,1,increment
#Loop repetition
Up:
    addi $a0,$a0,1
    j Loop
#Increment word count and reset flag
increment:
    addi $v0,$v0,1
    addi $t1,$0,0
    j Up
#Set flag if space founs
space:
    addi $t1,$0,1
    j Up
#Return to mai
ret:
addi $v0,$v0,1
jr $ra
#Implementation of string uppercase function
Uppercase:
    #Get each charcter
    lb $t0,0($a0)
    #Check end of the string
    beq $t0,10,return
    #Small letter check
    bge $t0,97,next
#Increment address to get next charcter and loop repetition
up:
    addi $a0,$a0,1
    j Uppercase
#Check is small letter
next:
    bgt $t0,122,up
    #Then change into capital
    addi $t0,$t0,-32
    #Restore
    sb $t0,0($a0)
    j up
#go to main
return:
    jr $ra

--------------------------

Output

Enter a string: This is my program.
Words' count = 4
String after uppercasing = THIS IS MY PROGRAM.

-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Prompt the user and read in a string. Make your string large enough to hold 100...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Create a program that performs the following operations: Prompt for and accept a string of up...

    Create a program that performs the following operations: Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 # create space for string input • The syscall to place input into the buffer looks like: li $v0, 8 # code for syscall read_string la $a0, buffer # tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer...

  • Read a string then count the number of words in the string. Need to count the...

    Read a string then count the number of words in the string. Need to count the number of white spaces that include single blank space ' ', tab \t, new line \n. If a non-white space character is followed by a white space or NULL character then it is a word.

  • MIPS - Takes two inputs from the user, which are the lengths of two sides of...

    MIPS - Takes two inputs from the user, which are the lengths of two sides of a polygon. It adds those two lengths and prints the sum. Your task is modify the program to make it specific to a triangle, and to print the perimeter of that triangle. See blue highlighted. preamble: prompt1: prompt2: answer: endline: .data ascii .asciiz asciiz .asciiz asciiz .asciiz "\nThis program, written by <YOUR NAME>," " can be used to add the length of two sides...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • Question 2 Write a program that will read in a line of text up to 100...

    Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Write a C program to run on ocelot to read a text file and print it...

    Write a C program to run on ocelot to read a text file and print it to the display. It should optionally find the count of the number of words in the file, and/or find the number of occurrences of a substring, and/or take all the words in the string and sort them lexicographically (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring]...

  • (1) Prompt the user to enter a string of their choosing. Store the text in a...

    (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT