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

Build an assembly function that will sort an array of integers. Bubble sort algo

ID: 3574561 • Letter: B

Question

Build an assembly function that will sort an array of integers. Bubble sort algorithm can be used. The function receives the array and the array size from a C/C++ program. The array of integers should be created and populated with values inside the C/C++ program. After sorting, the C/C++ code should display the array in sorted order. For a greater flexibility, the user should be prompted for the number of elements in the array. The array could be loaded with random numbers

Need comments as well

EDIT: I need both C++ program and Assembly

Explanation / Answer

Created Program With Menu Options

Select Menu In proper way.

At start enter size of array.

Then Add elements using option 1.

Then Sort Them using 3rd option and display the sorted array in 2nd option.

#include<iostream>
using namespace std;

void accept(int Arr[], int s);
void display(int Arr[], int s);
void bsort(int Arr[],int s);

int main()
{
   int Arr[100],n,choice;
   cout<<"Enter Size of Array ";
   cin>>n;
   do
   {
       cout<<" MENU";
       cout<<" 1. Accept elements of array";
       cout<<" 2. Display elements of array";
       cout<<" 3. Sort the array using bubble sort method";
       cout<<" 4. Exit";
       cout<<" Enter your choice 1-4 :";
       cin>>choice;

       switch(choice)
       {
           case 1:   accept(Arr,n);
               break;
           case 2:   display(Arr,n);
               break;
           case 3:   bsort(Arr,n);
               break;
           case 4:   break;
           default:cout<<" Invalid choice";
       }
   }while(choice!=4);

   return 0;
}

void accept(int Arr[], int s)
{
   for(int I=0;I<s;I++)
   {
       cout<<"Enter element "<<I+1<<":";
       cin>>Arr[I];
   }
}

void display(int Arr[], int s)
{
   cout<<"The elements of the array are: ";
   for(int I=0;I<s;I++)
       cout<<Arr[I]<<" ";
}

void bsort(int Arr[],int s)
{
   int I,J,Temp;
   for(I=0;I<s-1;I++)
   {
       for(J=0;J<(s-1-I);J++)
           if(Arr[J]>Arr[J+1])
           {
               Temp=Arr[J];    //swapping
               Arr[J]=Arr[J+1];
               Arr[J+1]=Temp;
           }
   }
}

Assembly Function

BubbleSortDWord:
;Bubble sort of dword array
; Parameters:
; ESI - array address
; ECX - array length (number of elements)
.mMain:
dec ecx
cmp ecx,0
jl .mEx

push esi
push ecx
mov bl,0
.mOne:
mov eax,[esi]
cmp eax,[esi+4]
jle .mSkipR
mov edx,[esi+4]
mov [esi],edx
mov [esi+4],eax
mov bl,1
.mSkipR:
add esi,4
loop .mOne
pop ecx
pop esi

cmp bl,0
je .mEx
jmp .mMain
.mEx:

ret

Thank You...!!

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