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

3.5 Modify and submit the program \"Sum of Integers\" given in section 3.16 to u

ID: 3876280 • Letter: 3

Question

3.5 Modify and submit the program "Sum of Integers" given in section 3.16 to use the for- mula: If you're a bit rusty on the Sigma notation, the formula states that the summation of the integers from 1 to N can be calculated as N times (N+1) divided by two. Since either N or N+1 will be even, the product is even, and the result will be divisible by two. Since the product is positive you can use a shift to perform the division. Test your program on the MIPS simulator. What is the upper bound on N for the program to give a correct answer? How large does N need to be for you to detect an observable delay in the original program?

Explanation / Answer

Program:-

#data section

.data
summationNumber: .asciiz "Enter the number : "         # value of N entering
n: .word 4                                                                 #store value of N
summationvalue: .ascii "sigma(K=1->N) = "               #for out put display

#Main section
.text
la $a0,summationNumber                           #load summationnumber address
li $v0,4
syscall

li $v0,5                                                           #Read N value
la $a0,n
syscall

move $t0,$v0                                             #Move N into t0
li $t2,2                                                     #set t2=2
add $t1,$t1,$zero                                      #set t1=0

add $t1,$t1,$t0           #t1=n+1
addi $t1,$t1,1

mul $t1,$t1,$t0                                           #t1=(n+1)*n
div $t1,$t1,$t2        #t1=(n+1)*n/2

la $a0,summationvalue                          #load summation value
li $v0,4
syscall

move $a0,$t1                                        #display result
li $v0,1
syscall

exit:                                                 #end of the program
li $v0,10
syscall


Output

Enter the number : 569446
sigma(K=1->N) = 1073384581
-- program is finished running --


//UpperBound=569446

//After that wrong output

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