.text .global main main: addi $t4,$zero, 3 la $t0, P # loads the address of the
ID: 3609606 • Letter: #
Question
.text.global main
main: addi $t4,$zero, 3
la $t0, P # loads the address of the first element of the sequence,P(0), into register $t0
loop:
blt $t6,$zero,exitloop
lw $t1, ($t0) # loads the value of P(0) into register $t1.
lw $t2, 4($t0) # loads the value of P(1) into register $t2
add $t1, $t2, $t3 # adds the values of P(0) and P(1), leaving theresult in register $t3.
sw $t3,12($t0) # stores the value in the array location associatedwith P(3).
addu $t4, $t3, $t4
addi $t0,$t0, 4
j loop
exitloop: li $v0, 4
la $a0, message
syscall
li $v0, 1 #printing thevariable k where the loop ends
move $v0, $t7
syscall
li $v0,4 #printing new linecharacter
la $v0, cr
syscall
#################################################
# #
# data segment #
# #
#################################################
.data
message: .asciiz "Overflow occurred when adding element "
cr: .asciiz " "
P: .word 1,1,1 # This is the same label ‘P’ at which weinitialize the first 3
# elements of the array to 1 that was mentionedabove.
.space 300 # This reserves a further 300 bytes of space immediatelyfollowing
# the three 4-byte words with 1 , 1 , 1 at label ‘P’above. 300 bytes
# should be enough because you should find that overflow occurs
# when you add element P(73) of the array to the running sum.
##End
Please help
Explanation / Answer
please rate - thanks changed lines in red - I think I have them allhighlighted .text .globl main main: addi $t4,$zero, 3 la $t0, P # loads the address of the first element of the sequence,P(0), into register $t0 loop: # blt $t6,$zero,exitloop commented out lw $t1, ($t0) # loads the value of P(0) into register $t1. lw $t2, 4($t0) # loads the value of P(1) into register $t2 addu $t3, $t2, $t1 # adds the values of P(0) andP(1), leaving the result in register $t3. blt $t3,$zero,exitloop sw $t3,12($t0) # stores the value in the array location associatedwith P(3). addu $t4, $t3, $t4 addi $t0,$t0, 4 j loop exitloop: li $v0, 4 la $a0, message syscall li $v0, 1 #printing thevariable k where the loop ends move $v0, $t7 syscall li $v0,4 #printing newline character la $v0, cr syscall ################################################# # # # datasegment # # # ################################################# .data message: .asciiz "Overflow occurred when adding element " cr: .asciiz " " P: .word 1,1,1 # This is the same label ‘P’ at which weinitialize the first 3 # elements of the array to 1 that was mentioned above. .space 300 # This reserves a further 300 bytes of space immediatelyfollowing # the three 4-byte words with 1 , 1 , 1 at label ‘P’above. 300 bytes # should be enough because you should find that overflow occurs # when you add element P(73) of the array to the running sum. ##End
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.