Question

Translate the following C code to MIPS assembly code. Assume that the value of i is...

Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray

if (i > 10)

MemArray[i] = 0;

else

MemArray[i] = -MemArray[i];

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

I considered it as word directive; if any other accordingly offset will change

MIPS PROGRAM :-


li $t1, 10
sll $t2, $t0, 2           #offset for i
add $t3, $s0, $t2       #address of MemArray[i]
bgt $t0,$t1,IF_CON       #condition
ELSE:                   #else body
   lw $t4,0($t3)
   sub $t4, $0, $t4   #changing sign
   sw $t4,0($t3)
   j NEXT
IF_CON:                   #if body
   li $t4,0
   sw $t4,0($t3)       #storing zero
NEXT:

Add a comment
Know the answer?
Add Answer to:
Translate the following C code to MIPS assembly code. Assume that the value of i is...
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
ADVERTISEMENT