Question: Translate this C/C++ code fragment to MIPS assembly language. You are only allowed to use the MIPS instructions given in the list below. (The variable

Translate this C/C++ code fragment to MIPS assembly language. You are only allowed to use the MIPS instructions given in the list below. (The variable declarations are for your reference; you dont have to show the data allocation section.)

You have to use these register allocations:

  • &x[0] is in $x
  • &y[0] is in $y
  • i is in $i
  • j is in $j

You may use any other registers as temporaries. Write efficient code. Obviously inefficient code will be penalized. (60 points)

int x[100], y[100], i, j;

[some code not shown ]

i=3;

j=2;

while (x[i] < j) {

j*=2;

y[i-1] = j;

if (i > 94)

break;

i+=3;

}

MIPS instruction list:

[rs, rt, rd are any registers. I is a 16-bit constant.]

add rd, rs, rt rd = rs + rt

sub rd, rs, rt rd = rs - rt

addu rd, rs, rt rd = rs + rt (overflow ignored)

subu rd, rs, rt rd = rs - rt (overflow ignored)

addiu rt, rs, I rt = rs + I (sign-extended)

mul rd, rs, rt rd = rs * rt

div rd, rs, rt rd = rs / rt

rem rd, rs, rt rd = rs % rt

and rd, rs, rt rd = rs & rt

or rd, rs, rt rd = rs | rt

andi rt, rs, I rt = rs & I (zero-extended)

ori rt, rs, I rt = rs | I (zero-extended)

sll rd, rt, I rd = rt << I

srl rd, rt, I rd = rt >> I

lw rt, I(rs) rt = Mem[rs + I] (load word)

sw rt, I(rs) Mem[rs + I] = rt (store word)

lbu rt, I(rs) rt = mem[rs + I] (load byte zero-extended)

lb rt, I(rs) rt = mem[rs + I] (load byte sign-extended)

sb rt, I(rs) Mem[rs + I] = rt (store byte)

beq rs, rt, label if (rs == rt) goto label

bne rs, rt, label if (rs != rt) goto label

blt rs, rt, label if (rs < rt) goto label

ble rs, rt, label if (rs <= rt) goto label

bgt rs, rt, label if (rs > rt) goto label

bge rs, rt, label if (rs >= rt) goto label

slt rd, rs, rt if (rs < rt) rd = 1; else rd = 0

slti rt, rs, I if (rs < I) rd = 1; else rd = 0

j label goto label

jr rs PC = rs

jal label $31 = return address; goto label

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!