Mix (C++ and Assembly) Program to Convert BCD Number into Binary Format

#include<iostream.h>
#include<conio.h>
void main()
{
int a;
cout<<"\n Enter a BCD number:";
cin>>a;
int t;
int r=0;
int i;
asm{
mov ax,a
ror ax,1
ror ax,1
ror ax,1
ror ax,1
ror ax,1
ror ax,1
ror ax,1
ror ax,1
and ax,000fh
mov i,ax
}
r=r*10+i;
asm{
mov ax,a
ror ax,1
ror ax,1
ror ax,1
ror ax,1
and ax,000fh
mov i,ax
}
r=r*10+i;
asm{
mov ax,a
and ax,000fh
mov i,ax
}
r=r*10+i;
cout<<"\n Binary Equivalent:"<<r;
getch();
}
/* Output
 Enter a BCD number:54
 Binary Equivalent:36
*/

Leave a Reply

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