Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Q1:
- A: .word
- C: .word 10
- Index: .word 0
- list: .word 1, 2, 3, 4, 5, 0, 0, 0, 0, 0
- .text
- li $t0, 10 # t0 is a constant 10 li $t1, 0 # t1 is our counter (i) loop: beq $t1,$t0, end #if t1==10 we are done
- dsll $t3, $t1, 3 ld $t4 , list($t3)
- daddi $t5, $t5, t4
- sd $t5, result
- addi$t1,$t1,1 #add1tot1 j loop # jump back to the top end:
- end:
- halt
- Q2:
- .data
- C: .word 10
- Index: .word 0
- list: .word 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
- .text
- main:
- ld r1, C(r0)
- ld r2, Index(r0)
- beq $r1,$r2, end; if (r1 = r2) then exit
- ld $t1, Index(r0)
- dsll $t1, $t1, 3; $t1 = 8 * $t1, save value into r4
- ld r4,list($t1)
- daddi $t1, $t1, 8
- ld r5,list($t1)
- daddy r3, r4, r5, ; add value at current index and next index together, save value into r3
- daddi $t1, $t1, 8
- sd r3, list($t1)
- daddi r2, r2, 1
- sd r2, Index(r0)
- j main
- exit:
- halt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement