In this post, we will write programs in 8085 Assembly Language for Packing and unpacking of BCD numbers.

Packing & Unpacking of BCD numbers: 8085 programming

## Packing of BCD numbers: 8085 programming

**Problem statement: **

Pack the two unpacked 4-bit single digit BCD numbers stored in memory locations C200H and C201H and store result in memory location C300H. Assume the least significant digit is stored in C200H.

**Input Data:**

Memory Address(H) | Data(H) |

C200C201 | 04 09 |

**PROGRAM** (8085 assembly code) for Packing of BCD numbers

Memory Address(H) | Machine Code(H) | Label | Mnemonics(Instruction) | Comments |

C000 C001 C002 | 3A01 C2 | LDA C201H | Get the Most significant BCD digit | |

C003 C004 C005 C006 | 07 07 0707 | RLC RLC RLC RLC | Adjust the position of the second digit (09 is changed to 90) | |

C007 C008 | E6 F0 | ANI FOH | Make least significant BCD digit zero | |

C009 | 4F | MOV C, A | store the partial result | |

C00AC00B C00C | 3A 00 C2 | LDA C200H | Get the lower BCD digit | |

C00D | 81 | ADD C | Add lower BCD digit | |

C00EC00F C010 | 32 00 C3 | STA C300H | Store the result | |

C011 | 76 | HLT | Terminate program execution |

BCD NO.: The numbers “0 to 9” are called BCD (Binary Coded Decimal) numbers.

**Result**

Memory Address(H) | Data(H) |

C300 | 94 |

## Unpacking of BCD numbers: 8085 programming

**Problem statement: **

Unpack the two digit BCD number in memory location C200H and store the two digits in memory locations C300H and C301H, such that memory location C300H will have lower BCD digit

**Input Data:**

Memory Address(H) | Data(H) |

C200 | 58 |

**PROGRAM** (8085 assembly code) for Unpacking of BCD numbers

Memory Address(H) | Machine Code(H) | Label | Mnemonics(Instruction) | Comments |

C000 C001 C002 | 3A 00 C2 | LDA C200H | Get the 2 digit packed BCD number | |

C003 C004 | E6 F0 | ANI FOH | Mask lower nibble | |

C005 C006 C007 C008 | 0F 0F 0F 0F | RRC RRC RRC RRC | Adjust higher BCD digit as a lower digit | |

C009 C00A C00B | 32 00 C3 | STA C300H | Store the partial result | |

C00C C00D C00E | 3A 00 C2 | LDA C200H | Get the original BCD number | |

C00F C010 | E6 0F | ANI OFH | Mask higher nibble | |

C011 C012 C013 | 32 01 C3 | STA C301H | Store the result | |

C014 | 76 | HLT | Terminate program execution |

**Result**

Memory Address(H) | Data(H) |

C300 C301 | 08 05 |