8085 Program to convert an 8-bit binary to BCD

MicrocontrollerMicroprocessor8085

In this program we will see how to convert binary numbers to its BCD equivalent.

Problem Statement

A binary number is store dat 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

AddressData
.
.
.
.
.
.
800034
.
.
.
.
.
.

Flow Diagram

Program

AddressHEX CodesLabelsMnemonicsComments
F00021, 00, 80
LXI H,8000HInitialize memory pointer
F00316, 00
MVI D,00HClear D- reg for Most significant Byte
F005AF
XRA AClear Accumulator
F0064E
MOV C, MGet HEX data
F007 C6, 01LOOPADI 01HCount the number one by one
F009 27
DAAAdjust for BCD count
F00AD2, 0E, F0
JNC SKIPJump to SKIP
F00D 14
INR DIncrease D
F00E0DSKIPDCR CDecrease C register
F00FC2, 07, F0
JNZ LOOPJump to LOOP
F0126F
MOV L, ALoad the Least Significant Byte
F01362
MOV H, DLoad the Most Significant Byte
F01422, 50, 80
SHLD 8050HStore the BCD
F01776 
HLTTerminate the program


Output

AddressData
.
.
.
.
.
.
805052
.
.
.
.
.
.
raja
Published on 21-Jan-2019 15:12:41
Advertisements