68.8k views
4 votes
Question 2Write a MIPS assembly implementation of the following C/C++ code. Assume small, unsigned integer arithmetic (no range checking or dealing with negatives needed). Also assume variable names are defined in .data, so you will need to load/store them appropriately.

if(Num1 Result = Num1;
else if (Num1 = Num2)
Num3;

else Result = Num3 + 5

User Joscani
by
6.2k points

1 Answer

7 votes

Answer:

Please kindly check explainations for the code.

Step-by-step explanation:

lw $t1, Num1

lw $t2, Num2

lw $t3, Num3

blt $t1, $t2, if

beq $t1, $t2, elseif

else:

add $t0, $t3, 5

sw $t0, Result

endif:

#.....other statements after if-elseif-else

if:

sw $t1, Result

b endif

elseif:

ble $t2, $t3, if2

or $t0, $t1, $t3

sw $t0, Result

b endif

if2:

and $t0, $t2, $t3

sw $t0, Result

b endif

Go to attachment for the onscreen code.

Question 2Write a MIPS assembly implementation of the following C/C++ code. Assume-example-1
User Mark Lagendijk
by
6.6k points