Question

int a = 200;    // $1 int b = 500; // $2 int xMax =...

int a = 200;    // $1
int b = 500; // $2
int xMax = 1000; // $3
int yMax = 2000; // $4


if (xMax < a){
a = xMax;
}

if (yMax < b){
b = yMax;
}

How would I translate the above C code into MIPS assembly language?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
using $1 as a, $2 as b, $3 as xMax, $4 as yMax, and $5, $6, ... as temporary variables.

li $1, 200  # int a = 200;
li $2, 500  # int b = 500;
li $3, 1000 # int xMax = 1000;
li $4, 2000 # int yMax = 2000;

if1:    
    bge $3, $1, end1    # if xMax >= a, then don't execute the loop body
    addi $1, $0, $3     # a = xMax;
end1:

if2:    
    bge $4, $2, end1    # if yMax >= b, then don't execute the loop body
    addi $2, $0, $4     # b = yMax;
end2:
Add a comment
Know the answer?
Add Answer to:
int a = 200;    // $1 int b = 500; // $2 int xMax =...
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