What is the value in s1 when the program gets to label done

What is the value in $s1 when the program gets to label \"done\"?

Solution


       li $s0, 3           //li stands for load immediate, which will copy the value to the specified register. So, $s0 = 3.
       li $s1, 0            //li stands for load immediate, which will copy the value to the specified register. So, $s1 = 0.
loop:
       beq $s0, $zero, done   //beq stands for branch if equal, If the valud of $s0, equals the value in $zero, branch to done. if($s0 == 0) done.
                               //This is false for the first time this statement is executed. As, $s0 is holding a value of 3.
                               //This is false for the second time this statement is executed. As, $s0 is holding a value of 2.
                               //This is false for the third time this statement is executed. As, $s0 is holding a value of 1.
                               //This is true for the fourth time this statement is executed. As, $s0 is now holding a value of 0,
                               //And $s0, $zero values are equal, now the branch will happen, and will be branched to the label done.
       subi $s0, $s0, 1       //subi stands for subtract immediate. $s0 = $s0 - 1; which means the decrement.
                               //For the first time this statement is executed, $s0-- which will decrement $s0 value to 2.
                               //For the second time this statement is executed, $s0-- which will decrement $s0 value to 1.
                               //For the third time this statement is executed, $s0-- which will decrement $s0 value to 0.
       addi $s1, $s1, 5       //addi stands for add immediate. $s1 = $s1 + 5;
                               //For the first time this statement is executed, $s1 += 5 will update $s1 value to 5.
                               //For the second time this statement is executed, $s1 += 5 will update $s1 value to 10.
                               //For the third time this statement is executed, $s1 += 5 will update $s1 value to 15.
       j loop                   //j stands for unconditional jump. So, jump to loop.
done:
//At this point, $s1 is holding the value of 15, $s0 is holding the value of 0.

 What is the value in $s1 when the program gets to label \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site