Question

Assume that k correspond to register $s0 and the base of the array v is in...

Assume that k correspond to register $s0 and the base of the array v is in $s1. What is the MIPS assembly code corresponding to this C segment?

If ( V[K]< V[K+1]) {

temp = v[k];

v[k] = v[k+1];

v[k+1] = temp;

}

else {

v[k] = k; v[k+1]=k+1

}

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

please find the answer below::

mul $t0,$s0,4 #get address of k
add $t1,$t0,$s1 #get address of v[k]
add $t2,$t1,4 #get address of v[k+1]

lw $t3,($t1) #get value of v[k]
lw $t4,($t2) #get value of v[k+1]

blt $t3,$t4,ifPart
elsePart:
lw $s0,($t1) #v[k] = k
add $s0,$s0,1 #get k+1
lw $s0,($t2) #v[k+1] = k+1

j exit
ifPart:

lw $t0,($t1) #get temp = v[k]

lw $t1,($t2) #get v[k+1]
sw $t1,($t0) #v[k] = v[k+1]
lw $t0,($t1) #v[k+1] = temp

exit:

Edit Execute cToMips1212.asmcToMips121.asm mul şt0 ,$80,4 #get address of k add $t1,$t0,$s1 #get address of v[k] add 3 $t2, $

Add a comment
Know the answer?
Add Answer to:
Assume that k correspond to register $s0 and the base of the array v is in...
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