# Program to convert BCD to HEX in 8085 Microprocessor

Here we will see one 8085 program, that program will convert BCD numbers to HEX equivalent.

Problem Statement

A BCD number is stored at location 802BH. Convert the number into its binary equivalent and store it to the memory location 802CH.

Discussion

In this problem we are taking a BCD number from the memory and converting it to its binary equivalent. At first we are cutting each nibble of the input. So if the input is 52 (0101 0010) then we can simply cut it by masking the number by 0FH and F0H. When the Higher order nibble is cut, then rotate it to the left four times to transfer it to lower nibble.

Now simply multiply the numbers by using decimal adjust method to get final decimal result.

Data

802B
52

## Program

HEX Codes
Labels
Mnemonics
8000
31, FF, 80

LXI SP,80FFH
Initialize stack pointer
8003
21, 2B, 80

LXI H, 802BH
Pointer to the IN-BUFFER
8006
01, 2C, 80

LXI B, 802CH
Pointer to the OUT-BUFFER
8009
7E

MOV A, M
Move the contents of 802BH to A
800A
CD, 0F, 80

CALL BCDBIN
Subroutine to convert a BCD number to HEX
800D
02

STAX B
Store Acc to memory location pointed by BC
800E
76

HLT
Terminate the program
800F
C5
BCDBIN
PUSH B
Saving B
8010
47

MOV B, A
Copy A to B
8011
E6, 0F

ANI 0FH
Mask of the most significant four bits
8013
4F

MOV C, A
Copy A to C
8014
78

MOV A, B
Copy B to A
8015
E6, F0

ANI F0H
Mask of the least significant four bits
8017
0F

RRC
Rotate accumulator right 4 times
8018
0F

RRC

8019
0F

RRC

801A
0F

RRC

801B
57

MOV D, A
Load the count value to the Reg. D
801C
AF

XRA A
Clear the contents of the accumulator
801D
1E, 0A

MVI E, 0AH
Initialize Reg. E with 0AH
801F
83
SUM
Add the contents of Reg. E to A
8020
15

DCR D
Decrement the count by 1 until 0 is reached
8021
C2, 1F, 80

JNZ SUM

8024
81

Add the contents of Reg. C to A
8025
C1

POP B
Restoring B
8026
C9

RET
Returning control to the calling program

## Output

Data

802C
34

Updated on: 09-Oct-2019

638 Views