Mix (C++ and Assembly) Program to Search an Element in an Array

#include<iostream.h>
#include<conio.h>
void main()
{
int nos[10],j,t;
int i,p;
cout<<"\n Enter 10 numbers:";
for(i=0;i<10;i++)
{
cin>>nos[i];
}
cout<<"\n Enter number to be searched:";
cin>>j;
for(i=0;i<10;i++)
{
p=i;
t=nos[i];
_asm{
mov ax,t
mov bx,j
cmp ax,bx
jz out
}
}
cout<<"\n No is not found.";
goto end;
out:
cout<<"\n Number is found at "<<p+1<<" th position";
end:
getch();
}
/* Output
 Enter 10 numbers:15
20
48
32
14
5
36
84
11
37
 Enter number to be searched:5
 Number is found at 6 th position
*/

Leave a Reply

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