Question

How can I express this C language code "loops" to MIPS language program. Thank you int main() { ...

How can I express this C language code "loops" to MIPS language program. Thank you

int main()
{
   int Z=2;
   int i;

   i=0;
   while(1){
     if(i>20)
       break;
    Z++;
    i+=2;
   }
 
   do {
      Z++;
   } while (Z<100);
  
   while(i > 0) {
      Z--;
      i--;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MIPS assembly code for the C program:

===================

main:
   li $t2,2   # Z=2
   li $t0,0   # i=0
  
L1:    beq $t0,20,skip       # if (i >20)
   blt $t0,20,skip
   j L2           # break
skip:    add $t2,$t2,1       # Z++
   add $t0,$t0,2       # i+=2
   j L1           # while(1)
L2:   add $t2,$t2,1       # do Z++
   blt $t2,100,L2       # while (Z<100)
L3:   beq $t0,0 exit       # while i>0
   add $t2,$t2,-1       # Z--
   add $t0,$t0,-1       # i--
   j L3
exit:

====================

Add a comment
Know the answer?
Add Answer to:
How can I express this C language code "loops" to MIPS language program. Thank you int 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
ADVERTISEMENT