Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate the following high level language code to MIPS assuming that the varia

ID: 3689410 • Letter: T

Question

Translate the following high level language code to MIPS assuming that the variables a, b, c and d are available in the registers $t0, $t1, $t2 and $t3. Hints: different types of shift instructions discussed in class can do certain types of multiplication and division. Do not use multiplication and division instructions mult and div for this problem. Write the fully functioning MIPS code.

int a = 0x0077abcd;
int b = 16 * a ; // the * operator is multiplication
int c = 0xba70cb0;
int d = c / 8; // the / operator is integer division

if ( a > b )
    d = a * 2;
else
    c = b * 4;

Explanation / Answer

Solution is in below steps:

1. Calculation of c:

Multiplication is equavalent to left shifting the variabe with the multiplier value(+reminder if multiplier is not 2 power n)

Here c = 16 * a

This can be re-written as

c = a * 24 = a<<4 = 0x0077abcd * 0x04 = 0x01DEAF34

Therefore, $t2 will be manuplated as:

2. Calculation of d:

Division is equavalent to Right shifting the variabe with the multiplier value(-reminder if multiplier is not 2 power n)

Here d = c / 8

This can be re-written as

d = c / 23 = c>>3 = 0x0A48C39E >> 3 = 0x01491873

Therefore, $t3 will be manuplated as:

3. Converting the high level to low level

bgt $t0, $t1, ELSE # jump to ELSE if $t0 > $t1
sll $t3, $t0, 1       # d = a * 2
j ENDIF               # Jump to end of if-then-else condition

ELSE:

sll $t2, $t1, 2       # c = b * 4

ENDIF:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote