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

Compiling MIPS Code Give the shortest sequence of MIPS assembler instructions to

ID: 3600900 • Letter: C

Question

Compiling MIPS Code

Give the shortest sequence of MIPS assembler instructions to implement the C code

              for (i=0; i<=10; i=i+1)

          for (j=0; j<=10; j=j+1)

                 a[i][j] = b[j][i] + c;

Assume that a and b are 11 x 11 arrays of word values (integers), and that the base address of a is in $a0 and the base address of b is in $a1. Register $t0 holds the variable i (that has been initialized to zero prior to entering your code). Register $t1 holds the variable j (that has been initialized to zero) and register $s0 holds the byte variable c. The constant 11 has been loaded into register $s1. (The only pseudoinstruction you can use is mul dest src1 src2).

Outer:                 slt           $t2, $t0, $s1

                                             beq           $t2, $zero, exit          # 0<=i<=10

inner:                 slt           $t2, $t1, $s1

                       beq           $t2, $zero, end_inner     # 0 <= j <= 10

                       add           $t2, $t0, $t0             # 2*i

                       add           $t2, $t2, $t2             # 4*i

                       mul           $t3, $t1, $s1             # 11*j

                       add           $t3, $t3, $t3             # 22*j

                       add           $t3, $t3, $t3             # 44*j

                       add           $t3, $t3, $a1             # b[j][i]

lw            $t4, 0($t3)               # load b[j][i]

add           $t4, $t4, $s0             # b[j][i]+c

                       add           $t2, $t1, $t1             # 2*j

                       add           $t2, $t2, $t2             # 4*j

                       mul           $t3, $t0, $s1             # 11*i

                       add           $t3, $t3, $t3             # 22*i

                       add           $t3, $t3, $t3             # 44*i

                       add           $t3, $t3, $a0             # a[i][j]

                       sw            $t4, 0($t3)         # a[i][j] = b[j][i] + c

                       addi          $t1, $t1, 1               # j ++

                       j             inner

end_inner:             addi          $t0, $t0, 1               # i ++

                       j             outer

How can this code be changed to just have a one dimensional array. ( a[i] = b[i] + c )

Explanation / Answer

slt $t1,$t0,$s1
beq $t1,$0,exit
inner:
slt $t1,$t0,$s1
beq $t1,$zero,end-inner
add $t1,$t0,$t0
add St1,$t1,$t1
add $t2,$t2,$a1
lw $t3,0($t2)
add $t3,$t3,$s0
mul $t2,$t0,$s1
add $t2,$t2,$t2
add $t2,$t2,$t2
add $t2,$t2,$a0
sw $t3,0($t2)
addi $t0,$t0,1

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