Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a MIPS program that analyzes a string. Ask a user to enter a string (sente

ID: 3599512 • Letter: W

Question

write a MIPS program that analyzes a string.

Ask a user to enter a string (sentence or paragraph of their choice). You may assume that the string will not be longer than 100 characters.

Print the string ( to screen), or print an appropriate error message if the string is empty Print a table showing the following information about the string:

the number of characters

the number of words

the number of sentences

the number of uppercase letters

the number of lowercase letters

the number of spaces

the number of punctuation marks

I use mars4.5 to do mips

Explanation / Answer

Code:-

.data
prompt .ascizz "enter the string "
userInput: .space 100
error_msg: .ascizz "Empty string....error.Please try again "
character_msg: .ascizz " the number of characters is :"
space_msg: .ascizz " the number of spaces is :"
sentence_msg: .ascizz " the number of sentences is :"
uppercase_msg: .ascizz " the number of uppercase alphabets is :"
lowercase_msg: .ascizz " the number of lowercase alphabets is :"
word_msg: .ascizz " the number of words is :"
punc_msg: .ascizz " the 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