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

PLEASE WRITE IN SIMPLE MIPS CODE ! THANK YOU ! Write a program in assembly that

ID: 3598519 • Letter: P

Question

PLEASE WRITE IN SIMPLE MIPS CODE ! THANK YOU !

Write a program in assembly that calculates the sum of all the numbers of a floating point array that are smaller than the user input. Assume you defined an array with 8 floating point elements in your program and you ask the user for a real number. The result will be shown in the output with an appropriate message. If there are no smaller numbers than the user input in your array, provide an appropriate message. Use array A-11.355 2.670 3.566 4.560 5.980 7.665 12.340 18.540 1 as the floating point array. For example: Please give a real number: 16.750 The answer is: 38.136

Explanation / Answer

Given below is the code with output. Please don't forget to rate the answer if it helped. Thank you.


.data
A: .float 1.355, 2.670, 3.566, 4.560, 5.980, 7.665, 12.340, 18.540
len: .word 8
sum: .float 0
prompt: .asciiz "Please give a real number :"
ansMsg: .asciiz "The answer is : "
notFoundMsg: .asciiz "There were no numbers smaller than the given value"
.text
#prmopt the user
li $v0 4
la $a0, prompt
syscall
#get floating point number input and store in $f1
li $v0, 6
syscall
mov.s $f1, $f0
l.s $f0, sum #initialize sum = 0 in f0
la $t0, A #base address of array
lw $t1, len #the length of the array
li $t2, 1 #counter for tracking current element in array
li $t3, 0 #counter to track how many elements were smaller
loop:
bgt $t2, $t1, end_loop #if couter greater than length of array
l.s $f2, ($t0) #get current array element into f2
c.le.s $f2, $f1 #check if f2 < f1
bc1f next
add.s $f0, $f0, $f2 #add to sum
add $t3, $t3, 1 #increment no of elements that were smaller
next:
add $t0, $t0, 4 #next array address
add $t2, $t2, 1 #increment counter
b loop
end_loop:
#check wheter or not we found some numbers that were smaller
beqz $t3, notFound
#display the sum
li $v0, 4
la $a0, ansMsg
syscall
#move the sum from f0 to f12 and display
li $v0, 2
mov.s $f12, $f0
syscall
b exit
notFound:
#display the notFoundMsg and exit
li $v0, 4
la $a0, notFoundMsg
syscall
exit:
#exit
li $v0, 10
syscall



output

Please give a real number :16.75
The answer is : 38.136
-- program is finished running --
Please give a real number :1.2
There were no numbers smaller than the given value
-- program is finished running --

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