Menu

Implement Code Risc Assembly Using Peter Higginson Simulatorthanks Void Hpsort Unsigned Lo Q43797354

Implement this code in risc assembly using Peter Higginsonsimulator.Thanks!

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

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

//input; ra is replaced on output by its sortedrearrangement.

{

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 to1 during the “hiring” (heap

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

//down to 1 during the “retirement-and-promotion” (heapselection) 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 rrato its proper

    //level.

j=l+l;

while (j <= ir) {

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

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

ra[i]=ra[j];

i=j;

j <<= 1;

} else break; //Found rra’s level. Terminate the sift-down.

}

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

}

}

Expert Answer


Answer to Implement this code in risc assembly using Peter Higginson simulator.Thanks! void hpsort(unsigned long n, float ra[]) //…

OR