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

Translate the following C code to MIPS. Try to use the minimum number of instruc

ID: 3585302 • Letter: T

Question

Translate the following C code to MIPS. Try to use the minimum number of instructions. Assume that the variables a, b, i, and j are stored in registers $s0, $s1, $t0, and $t1 respectively. Assume that registers $s1 and $s2 hold the base registers for arrays A and B.

(1) Simple loop

int i = 100
while(i > a){
      b = b + A[i]
      i = i – 1
}

(2) Complex loop

for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                        A[16*i] = B[4*j]
            }

}

(3) Simple function

int sqrDistance(int ax, int ay, int bx, int by){
            int dx = ax - bx
            int dy = ay – by
            return dx*dx + dy*dy
}

(4) Recursive function

int factorial(int n){
            if (n == 1) return 1
            return n * fact(n-1)
}

Explanation / Answer

Answer: (1) simple loop in to MIPS:

(2) Complex loop in to MIPS:

(3) Simple function in to MIPS:

(4) Recursive function in to MIPS:

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