8085 Program to convert a 16-bit binary number to BCD


Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to convert 16-bit binary data to BCD data.

Problem Statement:

Write 8085 Assembly language program to convert 16-bit binary data to BCD data. The binary data is stored at location 8000H and 8001H.

Discussion:

This problem is solved by implementing 16-bit counter. We are storing the 16-bit number at first, then decreasing the numbers one by one, and increasing the decimal value by adjusting the decimal value. To increase the value, we can use the INR instruction, but INR instruction does not affect the carry flag. So here we are using ADI 01H for increasing it by 1.

The binary number is taken from location 8000H and 8001H, and the final result is stored at location 8050H to 8052H.

Input:

Address
Data
.
.
.
.
.
.
8000
FF
8001
FF
.
.
.
.
.
.

Flow Diagram:

Program:

Address
HEX Codes
Labels
Mnemonics
Comments
F000
2A, 00, 80

LHLD 8000H
Initialize HL with 16-bit data
F003
11, 00, 00

LXI D,0000H
Clear DE register
F006
AF

XRA A
Clear A register
F007
C6, 01
LOOP
ADI 01H
Add 01 with A
F009
21

DAA
Adjust decimal
F00A
47

MOV B,A
Store A to B
F00B
D2, 1B, F0

JNC SKIP
If CY = 0, go to skip
F00E
7B

MOV A,E
Load E to A
F00F
C6, 01

ADI 01H
Add 01H with A
F011
27

DAA
Decimal adjust
F012
5F

MOV E,A
Get E from A
F013
D2, 1B,F0

JNC SKIP
If CY = 0, go to skip
F016
7A

MOV A,D
Take D to A
F017
C6, 01

ADI 01H
Add 01H with A
F019
27

DAA
Adjust decimal
F01A
57

MOV D,A
Load A to D
F01B
2B
SKIP
DCX H
Decrease DE
F01C
7C

MOV A,H
Load H to A
F01D
85

ORA L
OR A and L
F01E
78

MOV A,B
Load B to A
F01F
C2, 07, F0

JNZ LOOP
Jump to Loop
F022
EB

XCHG
Exchange DE and HL
F023
22, 51, 80

SHLD 8051H
Store HL content into memory
F026
32, 50, 80

STA 8050H
Store A to memory
F029
76

HLT
Terminate the program

Output:

Address
Data
.
.
.
.
.
.
8050
35
8051
55
8052
06
.
.
.
.
.
.


Updated on: 30-Jul-2019

884 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements