Question: MIPS Functions and the Stack Segment 7 . 6 In - Lab Tasks The function merge _ sort sorts array A recursively with the help

MIPS Functions and the
Stack Segment
7.6 In-Lab Tasks
The function merge_sort sorts array A recursively with the help of a second merge function.
Translate these two functions into MIPS code. Write a main function to allocate an array of n
elements dynamically, read the array, call merge_sort and then print the sorted array.
void merge_sort(int A[], int n){
if (n>1){
merge_sort ( &A[],n2; // Sort the first half
merge_sort( &A[n2],n-n2 Sort the second half
merge (&A[],n); // Merge the two halves
}
}
// merge the first n2 elements with the last (n-n2) elements
// merge is a leaf function that makes no function calls
void merge(int A[], int n){
int B[n]; // Allocated on the stack
int i=0,j=n2,k=0;
while ((A[i]A[j]){B[k++]=A[i++];}{B[k++]=A[j++];}(k=0;k
}
 MIPS Functions and the Stack Segment 7.6 In-Lab Tasks The function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!