0% found this document useful (0 votes)
60 views2 pages

MIPS Code Loop Optimization Example

The document describes a MIPS loop that: 1) Subtracts the value at B[8] from g and adds the value at A[i] 2) Increments i by j 3) Repeats the process until i does not equal h It provides the mapping of variables to registers and base addresses for the arrays. The summary rewrites the loop in C-like pseudocode and gives the final compiled MIPS code to implement the loop based on the provided mappings.

Uploaded by

Cantiah Kaviraj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

MIPS Code Loop Optimization Example

The document describes a MIPS loop that: 1) Subtracts the value at B[8] from g and adds the value at A[i] 2) Increments i by j 3) Repeats the process until i does not equal h It provides the mapping of variables to registers and base addresses for the arrays. The summary rewrites the loop in C-like pseudocode and gives the final compiled MIPS code to implement the loop based on the provided mappings.

Uploaded by

Cantiah Kaviraj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

i.

MIPS loop: g = g B[8] +A[i]; i = i +j; if (i!=h) goto loop;

A is an array of 80 elements. Variables g, h, i and j are associated with registers $S1, $S2, $S3 and $S4 respectively. Base of array A is $S5 and that of B is $S6.

Answer: Rewriting this: Do { g = g B [8] + A [i]; i = i + j; } while (i! =h) go to loop; Using the following mapping: g = $S1 , h =$S2 , i = $S3 and j = $S4 base address of A = $S5, Base address of B =$S6 Final Compiled MIPS Code: lw $t0 32($S6) add $t1 $S3 $S3 add $t2 $S1 $t1 add $t3 $s5 $t2 lw $t4 0($t3) add $t5 $to $t4 sub $s1 $s1 $t5 add $S3 $S3 $S4 bne $S3 $S2 Loop # $t0 =B[8] #$t1 = i+i #$t2 = 2i +2i #$t3 = Ba + $t2 # Load word # $t5 = B [8] + A [i]; # SS1 = B [8] + A [i] # $S3 = i + j # Go to loop #If (i!=h)

lw $t0,32($s6) add $t1,$s3,$s3 add $t2,$s1,$t1 add $t3,$s5,$t2 lw $t4,0($t3) add $t5,$t0,$t4 L1: j exit sub $s1,$s1,$t5 add $s3,$s3,$s4 bne $s3,$s2,L1 exit:

You might also like