8085 Program to convert a two-digit BCD to binary

MicrocontrollerMicroprocessor8085

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

Problem Statement

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

Discussion

In this problem we are taking a BCD number from the memory and converting it to its binaryequivalent. At first we are cutting each nibble of the input. So ifthe 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, thenrotate 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.

Input

AddressData
.
.
.
.
.
.
802B52
.
.
.
.
.
.

Flow Diagram

Program

AddressHEX CodesLabelsMnemonicsComments
800031, FF, 80
LXI SP,80FFHInitialize stack pointer
800321, 2B, 80
LXI H, 802BH Pointer to the IN-BUFFER
800601, 2C, 80
LXI B, 802CH Pointer to the OUT-BUFFER
80097E 
MOV A, M Move the contents of 802BH to A
800A CD, 0F, 80
CALL BCDBINSubroutine to convert a BCD number to HEX
800D 02
STAX B Store Acc to memory location pointed by BC
800E76
HLT Terminate the program
800F C5 BCDBINPUSH B Saving B
801047
MOV B, A Copy A to B
8011E6, 0F
ANI 0FH Mask of the most significant four bits
80134F 
MOV C, A Copy A to C
801478
MOV A, B Copy B to A
8015E6, F0
ANI F0H Mask of the least significant four bits
80170F 
RRC Rotate accumulator right 4 times
80180F
RRC 
80190F
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 83SUMADD E Add the contents of Reg. E to A
802015
DCR D Decrement the count by 1 until 0 is reached
8021C2, 1F, 80
JNZ SUM 
802481
ADD C Add the contents of Reg. C to A
8025C1 
POP B Restoring B
8026C9 
RET Returning control to the calling program


Output

AddressData
.
.
.
.
.
.
802C34
.
.
.
.
.
.
raja
Published on 21-Jan-2019 15:08:44
Advertisements