In: Computer Science
Write a mips program that would function in QTSPIM that asks the user to enter a list of integer values, one per line, with the last value being a negative. The program should read in these integers until a negative number is entered. Afterwards the program should print 1) sum, 2) minimum value, 3) max value, 4) mean and 5) variance value. of the numbers that were entered.
ANSWER:
ScreenShot
--------------------------------------------------------------------------
Program
#Variable declaration
.data
list: .asciiz "Please enter values into the list:\n"
sList: .asciiz "Sum="
minList: .asciiz "\nMinValue="
maxList: .asciiz "\nMaxValue="
meanList: .asciiz "\nMeanValue="
varianceList: .asciiz "\nVarianceValue="
#Main program
.globl main
.text
main:
#Prompt user to enter list values
la $a0,list
li $v0,4
syscall
#Read values
li $v0,5
syscall
#For sum
li $s0,0
#for sum of squares
li $s3,0
#for counter
li $t0,0
#for min value
move $s1,$v0
#for max value
move $s2,$v0
#lsit enter loop until negative number enter
loop:
blt $v0,0,disp
#sum of all numbers
add $s0,$s0,$v0
#number of elements in the list
addi $t0,$t0,1
#Comparison for min number
bgt $s1,$v0,small
loop1:
#Comparison for max number
blt $s2,$v0,large
loop2:
#sum of each elements square sum
mul $v0,$v0,$v0
add $s3,$s3,$v0
#read next value
li $v0,5
syscall
#continue loop
j loop
#min value setting
small:
move $s1,$v0
j loop1
#max value setting
large:
move $s2,$v0
j loop2
#display values
disp:
#sum of the list elements display
la $a0,sList
li $v0,4
syscall
move $a0,$s0
li $v0,1
syscall
#min of the list elements display
la $a0,minList
li $v0,4
syscall
move $a0,$s1
li $v0,1
syscall
#max of the list elements display
la $a0,maxList
li $v0,4
syscall
move $a0,$s2
li $v0,1
syscall
#mean of the list elements display
la $a0,meanList
li $v0,4
syscall
#sum/N
div $t1,$s0,$t0
move $a0,$t1
li $v0,1
syscall
#variance of the list elements display
la $a0,varianceList
li $v0,4
syscall
#sigma(x^2/N)
div $t2,$s3,$t0
#Mean^2
mul $t1,$t1,$t1
#sigma(x^2/N)-Mean^2
sub $t2,$t2,$t1
move $a0,$t2
li $v0,1
syscall
#end of the program
exit:
li $v0,10
syscall
----------------------------------------------------------
Output
Please enter values into the list:
10
14
23
4
-5
Sum=51
MinValue=4
MaxValue=23
MeanValue=12
VarianceValue=66
If you do not get anything in this solution ,please put a comment and i will help you out .
Do not give a downvote instantly.It is a humble request.
If you like my answer,please give an upvote.....Thank you.