PhysicsTeacher.in

High School Physics + more

Packing & Unpacking of BCD numbers: 8085 programming

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

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)
C200
C201
04
09

PROGRAM (8085 assembly code) for Packing of BCD numbers

Memory Address(H)Machine Code(H)LabelMnemonics(Instruction)Comments
C000
C001
C002
3A
01
C2


LDA C201H

Get the Most significant BCD digit
C003
C004
C005
C006
07
07
07
07


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
C0094F
MOV C, A
store the partial result
C00A
C00B
C00C
3A
00
C2

LDA C200HGet the lower BCD digit
C00D81
ADD CAdd lower BCD digit
C00E
C00F
C010
32
00
C3

STA C300H
Store the result
C01176
HLT
Terminate program execution
program

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

Result

Memory Address(H)Data(H)
C30094

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)
C20058

PROGRAM (8085 assembly code) for Unpacking of BCD numbers

Memory Address(H)Machine Code(H)LabelMnemonics(Instruction)Comments
C000
C001
C002
3A
00
C2

LDA C200HGet 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 C200HGet the original BCD number

C00F
C010
E6
0F

ANI OFHMask higher nibble

C011
C012
C013
32
01
C3

STA C301HStore the result
C01476
HLTTerminate program execution

Result

Memory Address(H)Data(H)
C300
C301
08
05
See also  DAA Instruction in 8085 for BCD addition
Scroll to top
error: physicsTeacher.in