Program 3

Short Description:

This assignment is worth 40 points.

Goals

When you finish this homework, you should:

Formal Description

Write a program which will demonstrate sorting and searching algorithms.

You should implement the following program in MIPS assembly:


void RandomFill(int ary[], int size) {
    srand(time(NULL);
    int i;

    for (i=0;i<size;i++) {
	ary[i] = rand()% 1000;
    }
}

void PrintArray(int ary[], int size ){
    int i;

    for(i=0;i<size;i++) {
       
        cout << arry[i].number << " ";
        if (i % 10 == 9) {
	    cout << endl;
	}
    }
}

void BubbleSort(int array[], int size) {
   // you must implement this
}

void BinarySearch(array, size, key, found) {
   // you must implement this.  Non-recursively please
   // return 1 if the key is found
   // return 0 if the key is not found
}

void PrintFound(int num, int found) {
    cout << num << "was " ;
    if (found == 0) {
        cout << "not " ;
    }
    cout << "found in the array." << endl ; 
}

void main() {
   RandomFill(arr, 100)
   PrintArray(arr, 100)
   BubbleSort(arr, 100)
   BinarySearch(arr, 100, 10,found)
   PrintFound(10, found)
   BinarySearch(arr, 100, 200,found)
   PrintFound(200, found)
}

Please implement the following algorithms:

Input

None

Output

As described above.

Discussion

There are system calls for time, set seed, random int, and random range.

If you use any regesters that must be preserved across a call, you are responsible for doing this.

Submission

Please submit your MPIS file by Thursday April 1 at class time by email to danbennett360@gmail.com.