Assembly Language Program for Unpacking the Packed BCD number in 8085 Microprocessor

Binary coded decimal (BCD) is a way to express each of the decimal digits with a binary code. This means that each decimal digit, 0 through 9, is represented by a binary code of four bits.

Eg: 98 => 10011000

Unpacking the BCD number is separating each BCD digit.

Eg: 98 can be separated as 09 and 08. So we can say 10011000 [98] is packed and 00001001 [09] & 00001000 [08] are unpacked.


You might like to go through Step by step Process to add two packed BCD Numbers


Assembly language program to unpack the packed BCD number

// Manually store the packed BCD number [eg: 98 in this case] in the memory locations 3000H
// Store the result i.e, the unpacked numbers in the memory locations 3001H and 3002H
// For this Example result will be 09 and 08
// 3000<-09, 3001<-08

#ORG 0000H
#BEGIN 0000H

    LDA 3000H  //Get the packed BCD number from the memory
    MOV B,A
    MVI C,04
    ANI F0     // A = 90H

L1: RRC        // Need to be rotated right for 4 times to get A = 09H
    DCR C
    JNZ L1

    STA 3001
    MOV A,B
    ANI 0F     // A = 08H
    STA 3002
    HLT

#ORG 3000H
#DB 98H

Now when you would run the program it would give you the memory locations with the following values:

Unpacking BCD Number

Note: The above Hex codes have been assembled and simulated on Jubin’s 8085 Simulator.

Hope the post would help you. If any doubt, please mention the same in the comment section, we would revert back to you.

 

Leave a Reply

Your email address will not be published. Required fields are marked *