Question

SumMain($a0: &X, $a1: N, $v0: Sum) Write a function to find the sum of the main...

SumMain($a0: &X, $a1: N, $v0: Sum) Write a function to find the sum of the main diagonal elements in a two dimensional N by N array of 32-bit words. The address of the array and the size N are passed to the procedure in registers $a0 and $a1 respectively. The result is returned in $v0. The values in registers $a0 and $a1 should not be modified by this procedure. Calculate the number of clock cycles required to execute your algorithm, assuming N=4.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

Screenshot

code

       .text
summain:
       lw   $v0, 0($a0)   # first element is 0
       move   $t1, $a0
       addi   $t3, $a1, 1 # computing the offset
       sll   $t3, $t3, 2 # multiply the value by 4
       addi   $t0, $a1, -1 # initializing loop count
       blez   $t0, return
loop:   add   $t1, $t1, $t3   # calculating the next address
       lw   $t2, 0($t1) # t2 equal to Mem(t1)
       add   $v0, $v0, $t2   # adding the value to sum
       addi   $t0, $t0, -1 # decrementing the loop count
       bgtz   $t0, loop
return:   jr   $ra
---

all the best

Add a comment
Know the answer?
Add Answer to:
SumMain($a0: &X, $a1: N, $v0: Sum) Write a function to find the sum of the main...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT