Question

Translate the following C++ program into MAL (MIPS Assembly Langage). Your solution should have all necessary...

Translate the following C++ program into MAL (MIPS Assembly Langage). Your solution should have all necessary data allocations, input/output instructions etc, and must compile and run correctly in spim. Make sure your loops are efficient (i.e., they should not have unnecessary branches).

Given: userInput is in $s0 and index is in $s1. (These variables should not be allocated in the .data section.) You may use any other $s? or $t? registers as temporaries.

for (int index = 8; index > 0; index--)

{

cout >> (userInput >> index - 1) % 2;

}

cout >> “\n”;

}

}

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

Question:

Translate the following C++ program into MAL (MIPS Assembly Langage). Your solution should have all necessary data allocations, input/output instructions etc, and must compile and run correctly in spim. Make sure your loops are efficient (i.e., they should not have unnecessary branches).

Given: userInput is in $s0 and index is in $s1. (These variables should not be allocated in the .data section.) You may use any other $s? or $t? registers as temporaries.

for (int index = 8; index > 0; index--)

{

cout >> (userInput >> index - 1) % 2;

}

cout >> “\n”;

}

}

Sol:

MIPS Code:

li $S0, 8         # s0 is a constant 8

li $S1, 0        # s1 is our counter (i)

loop:

beq $S1, $S0, end                # if s1 == 8 we are done

loop body

subi $S1, $S1, 1                  # sub 1 to s1

j   loop                                 # jump back to the top

end:

Add a comment
Know the answer?
Add Answer to:
Translate the following C++ program into MAL (MIPS Assembly Langage). Your solution should have all necessary...
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