HW: MIPS (Part B)

15 pts total.

  1. Write MIPS assembly code for the following C function. Assume that A contains integer 0's and 1's representing the individual bits of a binary number. Do not use pseudo-instructions.
        int binToDec (int A[], int begin, int end)
          // precondition: A contains integer 0's and 1's
        {
            int k;
            int powOfTwo = 1;
            int decimal = 0;
            for(k = end; k >= begin; k--)
            {
                if ( A[k] == 1 )
                    decimal += powOfTwo;
                powOfTwo *= 2;
            }
            return decimal;
        }
    

    15 points