Question

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

2. Determine the length of the string which was entered. Every string that is entered will have a newline character (0x0a) appended to its end and then the null character (0x00). Do not count either of these characters when reporting the string length (stop scanning when you reach the newline character). You can use the la instruction to place the address of the buffer in a register. The lb (load byte is used just like lw) instruction can be used to read a byte from memory into a register (it will be placed on the right end of the register and the upper part of the register will be zeroed out.

3. Determine how many vowels are in the string.

4. Determine how many digits are in the string.

5. Determine how many spaces are in the string.

6. Subtract the sum of 3, 4, and 5 from the string length to determine how many other characters are in the string.

7. Your output should look approximately like this (user input is show in bold here):

Enter a string: a6cibDD734*^$D.#

Your string contains: 16 characters.

There are 2 vowels.

There are 4 digits.

There are 0 spaces.

There are 10 other characters.

8. Hint: It is probably less confusing to use a separate loop for each of the task from 3 to 6 rather than attempting to do all in a single loop…your choice, however

You will need to use .text and .data directives to define program and data areas in SPIM.

All characters in a string are represented in ASCII code.

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

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. Determine the length of the string which was entered. Every string that is entered will have a newline character (0x0a) appended to its end and then the null character (0x00). Do not count either of these characters when reporting the string length (stop scanning when you reach the newline character). You can use the la instruction to place the address of the buffer in a register. The lb (load byte is used just like lw) instruction can be used to read a byte from memory into a register (it will be placed on the right end of the register and the upper part of the register will be zeroed out.

3. Determine how many vowels are in the string.

4. Determine how many digits are in the string.

5. Determine how many spaces are in the string.

6. Subtract the sum of 3, 4, and 5 from the string length to determine how many other characters are in the string.

7. Your output should look approximately like this (user input is show in bold here):

Enter a string: a6cibDD734*^$D.#

Your string contains: 16 characters.

There are 2 vowels.

There are 4 digits.

There are 0 spaces.

There are 10 other characters.

Answer:

.data
prompt .ascizz "enter the string\n"
userInput: .space 100
error_msg: .ascizz "Empty string....error.Please try again\n"
character_msg: .ascizz "\nthe number of characters is :"
space_msg: .ascizz "\nthe number of spaces is :"
sentence_msg: .ascizz "\nthe number of sentences is :"
uppercase_msg: .ascizz "\nthe number of uppercase alphabets is :"
lowercase_msg: .ascizz "\nthe number of lowercase alphabets is :"
word_msg: .ascizz "\nthe number of words is :"
punc_msg: .ascizz "\nthe number of punctuations is :"

.text
.globl main
main:

la $a0,prompt
li $v0,4
syscall

li $v0, 8
la $a0, userInput
li $a1, 200
syscall

la $t0,userInput

#check for empty string
lb $t1,0($t0)
beq $t1,$zero,error_funct

#checking for conditions
la $t0,userInput
li $t2,0 #character count
li $t3,0 #space count
li $t4,0 #sentence count
li $t5,0 #upper_case count
li $t6,0 #lower_case count

loop:
lb $t1,0($t0)
beq $t1,$zero,prints

addi $t2,$t2,1

addi $t7,$0,32 #ascii for space

bne $t1,$t7,sentence_check
addi $t3,$t3,1

sentence_check:
addi $t7,$0,46 #ascii for dot

bne $t1,$t7,uppercase_check
addi $t4,$t4,1

uppercase_check:
addi $t7,$0,65 #ascii for A
bl $t1,$t7,lowercase_check
addi $t7,$0,90 #ascii for Z
bg $t1,$t7,lowercase_check

addi $t5,$t5,1

lowercase_check:
addi $t7,$0,97 #ascii for a
bl $t1,$t7,l_count_increment
addi $t7,$0,122 #ascii for Z
bg $t1,$t7,l_count_increment

addi $t6,$t6,1

l_count_increment:
addi $t0,$t0,1
b loop

prints:
la $a0,character_msg
li $v0,4
syscall

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

la $a0,space_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t3
syscall

la $a0,sentence_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t4
syscall

la $a0,uppercase_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t5
syscall

la $a0,lowercase_msg
li $v0,4
syscall

li $v0, 1
move $a0, $t6
syscall

la $a0,word_msg
li $v0,4
syscall

addi $t7,$t3,1

li $v0, 1
move $a0, $t7
syscall

la $a0,punc_msg
li $v0,4
syscall

#punctuation marks = total - spaces - uppercase count - lowercase count
sub $t7,$t2,$t3
sub $t7,$t7,$t5
sub $t7,$t7,$t6


li $v0, 1
move $a0, $t7
syscall

exit:
li $v0, 10
syscall


error_funct:
la $a0,error_msg
li $v0,4
syscall

li $v0, 10
syscall

Add a comment
Know the answer?
Add Answer to:
Create a program that performs the following operations: Prompt for and accept a string of up...
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
  • 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....

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

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

  • This program will require you to create a basic parser for an input string that is...

    This program will require you to create a basic parser for an input string that is somewhat like Python. Python has an older parser module and a newer ast module to manage pure Python syntax, but they won't be useful here. The program will read a data string, identify the control characters, and print out the overall structure of the string. Here's an example Input String: [{1}] Output: Number inside a dictionary inside a list Here are some basic rules...

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

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • QT Spim question. Program and answer already given please explaine it. Please explain the reason why...

    QT Spim question. Program and answer already given please explaine it. Please explain the reason why each instruction was used throughout the program step by step given the prompt, what is its purpose to achive the goal asked in the prompt, why is written in that order. Please not just write to the side what each instruction means in words like load $t0 to $t1. I want to understand the program thoroughly. Thanks in advance Previous information needed to solve...

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

  • Problem #1 Create a program that performs the following functions: Uses character arrays to read a...

    Problem #1 Create a program that performs the following functions: Uses character arrays to read a user's name from standard input Tells the user how many characters are in her name Displays the user's name in uppercase Create a program that uses the strstr() function to search the string "When the going gets tough, the tough stay put! for the following occurrences (display each occurrence found to standard output): "Going" "tou" "ay put!" Build a program that uses an array...

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