TITLE "BINBCD - Convert Binary digit in A to BCD" ;================================================================= ; Copyright (C) 1989 by Harold F. Bower. Permission granted to ; Alpha Systems Corp. to distribute with The Libraries, Version 4 ;----------------------------------------------------------------- PUBLIC BIN2BCD ;================================================================ ; BIN2BCD - Convert byte in A register to two packed BCD digits. ; Enter: A = Binary digit to be converted ; Exit : A = BCD form of entry digit ; All other registers unaffected/preserved ;================================================================ BIN2BCD: PUSH BC ; Affect only A register LD B,0FFH ; Preset counter BINBCL: INC B ; Bump output count SUB 10 JR NC,BINBCL ; Loop bumping counter til no more 10s ADD A,10 ; ..correct for underflow LD C,A ; Save low nybble here for a while LD A,B ; ..and bring hi one here.. ADD A,A ; Move it into position ADD A,A ADD A,A ADD A,A ADD A,C ; Add in Low nybble POP BC ; Restore regs RET END