Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Compiling MIPS Code Give the shortest sequence of MIPS assembler instructions to implement the C code for (i=0; i

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 )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

=+j Explain IHRMs role in global HR research.

Answered: 1 week ago

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago