Conversion of BCD Number to Binary Number in 8085

/*WAP to convert ten BCD numbers stored at 4350H to binary and store the result at 4360H*/

LXI SP,330AH ;initiate stack pointer
LXI H,4350H ;pointer to input table of BCD number
LXI B,4360H ;pointer to output table of equivalent binary
NEXTBYTE:
MOV A,M ;get BCD number
CALL BCT_BIN ;call BCTB_BIN conversion subroutine
STAX B ;store binary number to output table
MOV A,L ;copy reg. L to reg. A
CPI 59H ;compare it with value 59H
JZ HALT ;if it is 59H, then we have processed 10
;BCD numbers hence jump to HALT
INX H ;if it is not increment HL pair
INX B ;and increment BC pair
JMP NEXTBYTE ;and get next BCD
HALT:
HLT
BCT_BIN:
PUSH B ;save BC register
PUSH D ;save DE registers
MOV B,A ;save BCD number
ANI OFH ;mask most significant four bits
MOV C,A ;save unpacked BCD1 in C
MOV A,B ;get BCD again
ANI F0H ;mask least significant four bits
JZ BCD1 ;if BCD2=0, the result it only BCD1
RRC ;if not, convert most significant four
RRC ;bits into unpacked BCD2
RRC
RRC
MOV D,A ;save BCD2 in D
XRA A ;clear accumulator
MVI E,0AH ;set E as multiplier of 10
SUM:
ADD E ;add 10 until D=0
DCR D ;reduce BCD2 by one
JNZ SUM ;is multiplication complete?
;if not, go back and add again
BCD1:
ADD C add BCD1
POP D ;retrieve previous contents
POP B
RET

Leave a Comment