Program to convert HEX to BCD in 8085 Microprocessor


Here we will see one 8085 program that will convert binary numbers (HEX) to its BCD equivalent.

Problem Statement

A binary number is stored at location 800H. Convert the number into its BCD equivalent and store it to the memory location 8050H.

Discussion

Here we are taking a number from the memory, and initializing it as a counter. Now in each step of this counter we are incrementing the number by 1, and adjust the decimal value. By this process we are finding the BCD value of binary number or hexadecimal number.

We can use INR instruction to increment the counter in this case but this instruction will not affect carry flag, so for that reason we have used ADI 10H

Input

Address
Data


8000
34


 

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80


LXI H,8000H
Initialize memory pointer
F003
16, 00


MVI D,00H
Clear D- reg for Most significant Byte
F005
AF


XRA A
Clear Accumulator
F006
4E


MOV C,M
Get HEX data
F007 
C6, 01
LOOP
ADI 01H
Count the number one by one
F009 
27


DAA
Adjust for BCD count
F00A
D2, 0E, F0


JNC SKIP
Jump to SKIP
F00D 
14


INR D
Increase D
F00E
0D
SKIP
DCR C
Decrease C register
F00F
C2, 07, F0


JNZ LOOP
Jump to LOOP
F012
6F


MOV L,A
Load the Least Significant Byte
F013
62


MOV H,D
Load the Most Significant Byte
F014
22, 50, 80


SHLD 8050H
Store the BCD
F017
76


HLT
Terminate the program

 

Output

Address
Data


8050
52


Updated on: 09-Oct-2019

882 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements