# Homework Solution: Convert each of the following C statements into MIPS instructions. Assume that the variables a, b, and c are stored in \$s0, \$s…

Convert each of the following C statements into MIPS instructions. Assume that the variables a, b, and c are stored in \$s0, \$s1, and \$s2, respectively. The base addresses of the arrays A and B are stored in \$s3 and \$s4, respectively. Assume the arrays A and B contain integers. c = b + a [20^20] A [5] = a - b + 2^14 B [2] = A [3] + b - B [4] A [3] = B [b + c] - a + b

1) c = b + A[$2^{20}$]    ANS : MIPS transaltion for the above is :

Convert each of the aftercited C statements into MIPS instructions. Assume that the variables a, b, and c are stored in \$s0, \$s1, and \$s2, respectively. The deep addresses of the arrays A and B are stored in \$s3 and \$s4, respectively. Assume the arrays A and B inclose integers. c = b + a [20^20] A [5] = a – b + 2^14 B [2] = A [3] + b – B [4] A [3] = B [b + c] – a + b

## Expert Rejoinder

1) c = b + A[$2^{20}$]

ANS : MIPS transaltion coercion the overhead is :

lw \$t0, 4194304(\$s3)

sw \$t0, \$s2

2) A[5] = a – b + $2^{14}$

MIPS translation coercion the overhead legislation is as follows :

sub \$t0, \$s0, \$s1
sw \$t0, 20(\$s3)

3) B[2] = A[3] + b – B[4]

MIPS translation coercion the legislation is as follows :

lw \$t0, 16(\$s4)
sub \$t0, \$s1 , \$t0
lw \$t1, 12(\$s3)
lw \$t1,8(\$s4)

4 ) A[3] = B[b+c] – a + b

MIPS translation coercion the overhead legislation is as follows

lw \$t0,4*(\$0+\$1)(\$s4)
sub \$t0,\$t0,\$s0