Question: Implement this code in risc assembly using Peter Higginson simulator.Thanks! void hpsort(unsigned long n, float ra[]) //Sorts an array ra[1..n] into ascending numerical order using

Implement this code in risc assembly using Peter Higginson simulator.Thanks!

void hpsort(unsigned long n, float ra[])

//Sorts an array ra[1..n] into ascending numerical order using the Heapsort algorithm. n is

//input; ra is replaced on output by its sorted rearrangement.

{

unsigned long i,ir,j,l;

float rra;

if (n < 2) return;

l=(n >> 1)+1;

ir=n;

//The index l will be decremented from its initial value down to 1 during the hiring (heap

//creation) phase. Once it reaches 1, the index ir will be decremented from its initial value

//down to 1 during the retirement-and-promotion (heap selection) phase.

for (;;) {

if (l > 1) { //Still in hiring phase.

rra=ra[--l];

} else { //In retirement-and-promotion phase.

rra=ra[ir]; //Clear a space at end of array.

ra[ir]=ra[1]; //Retire the top of the heap into it.

if (--ir == 1) {// Done with the last promotion.

ra[1]=rra; //The least competent worker of all!

break;

}

}

i=l;// Whether in the hiring phase or promotion phase, we

//here set up to sift down element rra to its proper

//level.

j=l+l;

while (j <= ir) {

if (j < ir && ra[j] < ra[j+1]) j++; //Compare to the better underling.

if (rra < ra[j]) { //Demote rra.

ra[i]=ra[j];

i=j;

j <<= 1;

} else break; //Found rras level. Terminate the sift-down.

}

ra[i]=rra; //Put rra into its slot.

}

}

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!