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

I don\'t understand loops in MIPS yet... $a0 is an integer argument while $a1 is

ID: 3528762 • Letter: I

Question


I don't understand loops in MIPS yet...



$a0 is an integer argument while $a1 is a pointer to (ie: the address of) a large array. The value in $a0 can be any integer and the size of the array that $a1 points to is big enough (as long as you don't dereference memory before $a1, you won't be accessing memory that isn't yours) for the code to work correctly. Add comments to the code and then briefly explain what it does. Specifically, what is in the array as the function returns? Also, convert this MIPS code to C (you may find it easier to understand if you do this first!).

Explanation / Answer

func()

{

t1 = 31; // initializing t1 to 31

t0 = 31; // initializing t0 to 31

while(1){

t3=a0 >> t1; // right shifting a0 by t1 and storing in t3

t3 =t3 & 1; // restoring LSB of t3

t3 = t3 + 48; // adding 48 to t3

t4 = t0 - t1;

t2 = a1 + t4 ;

*t2 = t3; // storing t3 to address of (t2+0)

if(t1==0) break;

t1=t1-1;

}

*(t2+1)=0; // storing 0 at t2[1]

return ;

}