ICS 152, Problem Set 1

  1. Text Problem 2.6
  2. Bubble Sort
    You must write a MIPS assembly program to sort an array using the bubble sort algorithm. A C program implementing the bubble sort algorithm is shown below.

    void bubbleSort(int numbers[], int array_size)
    {
      int i, j, temp;
    
      for (i = (array_size - 1); i >= 0; i--)
      {
        for (j = 1; j <= i; j++)
        {
          if (numbers[j-1] > numbers[j])
          {
            temp = numbers[j-1];
            numbers[j-1] = numbers[j];
            numbers[j] = temp;
          }
        }
      }
    }
    
    

    The bubble sort function has two inputs, an array to sort and the array size. Assume that the array is in memory and $s0 holds the address of the start of the array. Assume that $s1 holds the size of the array.

  3. Text Problem 2.29
  4. Text Problem 2.37
  5. Text Problem 3.9
  6. Text Problem 3.10
  7. Text Problem 3.12