Mix (C++ and Assembly) Program to Find Reverse of an Array

#include<iostream.h>
#include<conio.h>
void main()
{
int nos[5],x,y;
cout<<"\n Enter 5 numbers:";
int i,j;
for(i=0;i<5;i++)
{
cin>>nos[i];
}
for(i=0,j=4;i<3;i++,j--)
{
x=nos[i];
y=nos[j];
_asm{
mov ax,x
mov bx,y
mov cx,ax
mov ax,bx
mov bx,cx
mov x,ax
mov y,bx
}
nos[i]=x;
nos[j]=y;
}
cout<<"\n Reverse:";
for(i=0;i<5;i++)
{
cout<<nos[i]<<" ";
}
getch();
}
/* Output
Enter 5 numbers:10
12
15
9
11
Reverse:11 9 15 12 10
*/

Leave a Reply

Your email address will not be published. Required fields are marked *

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