Find the MIPS code for the following statement A8 i Aj Var

Find the MIPS code for the following statement:

A[8] = i + A[j];

Variable i is assigned to $s0

Variable j is assigned to $s1

The base address of the array A is assigned to $s2

Solution

We need to know that address of the A[j] before we can load it into a temporary register.

To access an element in memory we must multiply it by 4 to account for byte addressing.

To accomplish this we perform the following sequence of operations:

           4i -->    First, i + i = 2i then 2i + 2i = 4i

lw $t0 32($s2)

add $t1 $s1 $s1

add $t1 $t1 $t1

add $t1 $t1 $s2

lw $t3 0($t1)

add $t0 $s0 $t3

   

Find the MIPS code for the following statement: A[8] = i + A[j]; Variable i is assigned to $s0 Variable j is assigned to $s1 The base address of the array A is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site