;Generalized Subroutine to convert binary number in [A] into its equivalent BCD number stored in RAM: ;Will return right most 2 digits in [A] ;No registers modified (INTEL) BINTOBCD: ;Convert binary number in [A] to BCD in RAM PUSH B ;Save BC register pair contents PUSH D ;Save DE register pair contents MVI B,64H ;Load divisor decimal 100 in B register MVI C,0AH ;Load divisor decimal 10 in C register MVI D,00H ;Initialize Digit 1 MVI E,00H ;Initialize Digit 2 STEP1: CMP B ;Check if number < Decimal 100 JC STEP2 ;if yes go to step 2 SUB B ;Subtract decimal 100 INR E ;update quotient JMP STEP1 ;go to step 1 STEP2: CMP C ;Check if number < Decimal 10 JC STEP3 ;if yes go to step 3 SUB C ;Subtract decimal 10 INR D ;Update quotient JMP STEP2 ;Continue division by 10 STEP3: STA Digit0 ;Store Digit 0 MOV A,D ;Get Digit 1 STA Digit1 ;Store Digit 1 RLC ;Shift it up 4 bits RLC RLC RLC ANI 0F0H MOV D,A ;Temp store in D MOV A,E ;Get Digit 2 STA Digit2 ;Store Digit 2 LDA Digit0 ORA D ;Add in 10's digit POP D ;Restore DE register pair POP B ;Restore BC register pair RET ;Return to main program Digit0: DB 0 ;Store for Bin->BCD Digit1: DB 0 Digit2: DB 0