Mix (C++ and Assembly) Program to Sort Numbers in Descending Order

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],x,y;
int i,j;
cout<<"\n Enter 5 Numbers:";
for(i=0;i<5;i++)
{
cin>>a[i];
}
//Sorting
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
x=a[j];
y=a[j+1];
asm{
mov ax,x
mov bx,y
cmp ax,bx
jge nxt
mov cx,ax
mov ax,bx
mov bx,cx
mov x,ax
mov y,bx
}
nxt:
a[j]=x;
a[j+1]=y;
}
}
cout<<"\n Sorted Array:";
for(i=0;i<5;i++)
cout<<a[i]<<" ";
getch();
}
/* Output
 Enter 5 Numbers:10
5
20
15
36
 Sorted Array:36 20 15 10 5
*/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.