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…

    Problem 3 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 I) c = b + A[220] 2) A[5] = a-b+214 3) B [2] = A [3] + b-B [4] 4) A [3] = B [b+c] -a + b
    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

    Expert Answer

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

    Problem 3 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 I) c = b + A[220] 2) A[5] = a-b+214 3) B [2] = A [3] + b-B [4] 4) A [3] = B [b+c] -a + b

    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)

    add $t0, $s1, $t0

    sw $t0, $s2

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

    MIPS translation coercion the overhead legislation is as follows :

    sub $t0, $s0, $s1
    add $t0, $t0, 16384
    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)
    add $t1, $t1, $t0
    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
    add $t0,$t0,$s1
    lw $t0,12($s3)