Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to convert the following C quicksort program to ARM assembler. There are

ID: 3833847 • Letter: Y

Question

You are to convert the following C quicksort program to ARM assembler. There are numerous websites that describe the quicksort algorithm. Your program must follow these conventions: 1. A calling function must use a stack to pass arguments to the called function. When the called function returns, it is the responsibility of the calling function to remove the arguments from the stack. 2. All registers that a called function will be using to perform calculations must first be pushed onto the stack along with the return address in r14. This is typically the first instruction of the function. When it is time for the function to return, the registers will be restored to their original values. The return address will be popped into the pc. 3. You may use any of the 4 stack types. 4. Make you program scalable so that it is easy to change the array size. 5. Your quicksort sorts an array of unsigned words (DCD into ascending order. 6. Before sorting you will need to copy the array to address 0x40000000. Here is a C implementation of a quicksort: void quicksort (unsigned int arr, int left, int right) int min E (left+right inti left; int j right, int pivot E arrmin]; while (left

Explanation / Answer

#include<stdio.h>

void swap (int a[], int left, int right)

{

int temp;

temp=a[left];

a[left]=a[right];

a[right]=temp;

}//end swap

void quicksort( int a[], int low, int high )

{

int pivot;

// Termination condition!

if ( high > low )

{

  pivot = partition( a, low, high );

  quicksort( a, low, pivot-1 );

  quicksort( a, pivot+1, high );

}

} //end quicksort

int partition( int a[], int low, int high )

{

int left, right;

int pivot_item;

int pivot = left = low;

pivot_item = a[low];

right = high;

while ( left < right )

{

  // Move left while item < pivot

  while( a[left] <= pivot_item )

   left++;

  // Move right while item > pivot

  while( a[right] > pivot_item )

   right--;

  if ( left < right )

   swap(a,left,right);

}

// right is final position for the pivot

a[low] = a[right];

a[right] = pivot_item;

return right;

}//end partition

// void quicksort(int a[], int, int);

void printarray(int a[], int);

int main()

{

int a[50], i, n;

printf(" Enter no. of elements: ");

scanf("%d", &n);

printf(" Enter the elements: ");

for (i=0; i<n; i++)

  scanf ("%d", &a[i]);

printf(" Unsorted elements: ");

printarray(a,n);

quicksort(a,0,n-1);

printf(" Sorted elements: ");

printarray(a,n);

}//end main

void printarray(int a[], int n)

{

int i;

for (i=0; i<n; i++)

  printf(" %d ", a[i]);

printf(" ");

}//end printarray

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote