# 8085 program to convert a BCD number to binary

**Problem –** Write an assembly language program for converting a 2 digit BCD number to its binary equivalent using 8085 microprocessor.

**Examples:**

Input : 72H (0111 0010)_{2}Output : 48H (in hexadecimal) (0011 0000)_{2}((4x16)+(8x1))=72

**Algorithm:**

- Load the BCD number in the accumulator
- Unpack the 2 digit BCD number into two separate digits. Let the left digit be BCD
_{1}and the right one BCD_{2} - Multiply BCD
_{1}by 10 and add BCD_{2}to it

If the 2 digit BCD number is 72, then its binary equivalent will be

7 x OAH + 2 = 46H + 2 = 48H

**Steps:**

- Load the BCD number from the memory location (201FH, arbitrary choice) into the accumulator
- Temporarily store the accumulator’s value in B
- Obtain BCD
_{2}by ANDing the accumulator with 0FH and store it in C - Restore the original value of the accumulator by moving the value in B to A. AND the accumulator with F0H
- If the value in the accumulator equals 0, then BCD
_{2}is the final answer and store it in the memory location, 2020H (arbitary) - Else, shift the accumulator to right 4 times to obtain BCD
_{1}. Next step is to multiply BCD_{1}by 0AH - Multiplication: Move BCD
_{1}to D and initialise E with 0AH as the counter. Clear the accumulator to 0 and add D to it E number of times - Finally, add C to the accumulator and store the result in 2020H

2020H contains the result.

ADDRESS | LABEL | MNEMONIC |
---|---|---|

2000H | LDA 201FH | |

2001H | ||

2002H | ||

2003H | MOV B, A | |

2004H | ANI 0FH | |

2005H | ||

2006H | MOV C, A | |

2007H | MOV A, B | |

2008H | ANI F0H | |

2009H | ||

200AH | JZ SKIPMULTIPLY | |

200BH | ||

200CH | ||

200DH | RRC | |

200EH | RRC | |

200FH | RRC | |

2010H | RRC | |

2011H | MOV D, A | |

2012H | XRA A | |

2013H | MVI E, 0AH | |

2014H | ||

2015H | SUM | ADD D |

2016H | DCR E | |

2017H | JNZ SUM | |

2018H | ||

2019H | ||

201AH | SKIPMULTIPLY | ADD C |

201BH | STA 2020H | |

201CH | ||

201DH | ||

201EH | HLT |

Store the BCD number in 201FH. 2020H contains its binary equivalent.

## Recommended Posts:

- 8085 program to convert gray to binary
- 8085 program to convert binary numbers to gray
- 8085 program to convert 8 bit BCD number into ASCII Code
- 8085 program to convert a hexadecimal number into ASCII code
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to convert an 8 bit number into Grey number
- 8085 code to convert binary number to ASCII code
- 8085 program for Binary search
- 8085 program to convert ASCII code into HEX code
- 8085 program to check whether the given number is even or odd
- 8085 program to reverse 16 bit number
- 8085 program to reverse 8 bit number
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to find square of a 8 bit number
- 8085 program to find nth power of a number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.