Ask Question

Add comments to the code and describe in one sentence what this code does. Assume that $a0 and $a1 are used for input and both initially contain the integers a and b, respectively. Assume that $v0 is used for the output. Also, convert this MIPS code to C

add $t0, $zero, $zero

loop: beq $a1, $zero, finish

add $t0, $t0, $a0

addi $a1, $a1, - 1

j loop

finish: addi $t0, $t0, 100

add $v0, $t0, $zero

+3
Answers (1)
  1. 19 March, 17:55
    0
    Code is given below:

    Explanation:

    It does a0*a1+100

    int func (int a0, int a1, int a2, int a3) / /In mips $a0 to $a4 are arguments to function

    {

    const int zero = 0; / / $zero is register whose value is always 0

    int t0 = zero; //t0 is temporary register

    while (a1!=0) / /beq is like a1! = 0 go out of loop

    {

    t0 = t0 + a0; //add a0 to "to" a1 times which is like a0*a1

    a1 = a1 - 1;

    }

    t0 = t0 + 100; //a0*a1+100

    return t0; / / return this value

    }

    int main ()

    {

    int a0, a1;

    printf ("Enter a0 and a1/n");

    scanf ("%d %d",&a0,&a1);

    printf ("%d*%d+100=%d/n", func (a0, a1,0,0));

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Add comments to the code and describe in one sentence what this code does. Assume that $a0 and $a1 are used for input and both initially ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers