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

Write a MIPS assembly language program that prompts the user for a line of text

ID: 3573425 • Letter: W

Question

Write a MIPS assembly language program that prompts the user for a line of text and reads the line typed by the user. If the line contains just white space characters your program should simply output the message "Line contains only white space characters." and stop. Otherwise, your program should computer and output the following. The number of non-whitespace characters in the line The number of words in the line The maximum length of a word in the line The minimum length of a word in the line The word of the maximum length in the line (If there happens to have two or more words of maximum length, print the word that appears last in the line.) The word of the minimum length in the line (If there happens to have two or more words of minimum length, print the word that appears last in the line.) Example: Suppose the line typed by the user is the following: It was the best of times and it was the worst of times. The output answer is as follows: Number of non-whitespace characters: 43 Number of words: 13 Maximum length of a word: 6 Minimum length of a word: 2 Word of maximum length: times. Word of minimum length: of Program outline: Prompt the user for a line of text Read the line of text typed by the user If the line has only whitespace characters Print the message "Line contains only white space characters." else Computer the quantities mentioned above and print the answers. Stop.

Explanation / Answer

.text

main:

la $a0, arrayone # $a0 This is the pointer to the array

addi $a1, $zero, 8 # $a1 = This is the number of elements in the array

jal maximumelement # "maximum" function call

j finish

maximum:

addi $t7, $zero, 0 # $t7 indexelement = 0

addi $t2, $zero, 0 # $t2 maximumSoFar = 0

newmaximum_loop:

# we will check if indexelement == number of elements in the array, exit loop

beq $t7, $a1, maximum_finish

lw $t3, 0($a0) # $t3 = arrayone[indexelement]

slt $t1, $t3, $t2 # if arrayone[indexelement] < maximumSoFar then $t1 = 1

# o/w, $t1 = 0

bne $t1, $zero, notmore # on the other hand if $t1 is not equal to $zero, then jump to notmore

addi $t2, $t3, 0 # maximumSoFar = arrayone[indexelement]

notmore:

addi $t7, $t7, 1 # indexelement = indexelement + 1

addi $a0,$a0, 4 # This is the point to the next element of the array

j newmaximum_loop

maximum_finish:

jr $ra

finish:

addi $a2, $t2, 0 # The $a2 now has maximum element

move $a0, $a2

li $v0, 1

syscall

.word 4,7,10,19,21,22,3,2,1,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote