PIC Microcontoller Radix Math Method

Binary to BCD half-packed 8 bit to 3 digit

From: Scott Dattalo, notes

 ;********************************
;binary_to_bcd - 8-bits
;
;Input
;  bin  - 8-bit binary number
;	A1*16+A0
;Outputs
; hundreds - the hundreds digit of the BCD conversion
; tens_and_ones - the tens and ones digits of the BCD conversion
binary_to_bcd:

	clr	hundreds
	mov	W, <>bin	;w  = A0*16+A1
	add	W, bin	;w  = A0+A1
	and	W, #00001111b	;w  = A0+A1 % 16
	snb	DC	;if A0+A1 > 16
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  0x16 		;  w  += 16
	mov	Hack, W
	mov	W, #$16	;  w  += 16
	add	W, Hack
	snb	DC	;if w % 16 > 10
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  0x06 		;  w  += 6
	mov	Hack, W
	mov	W, #$06	;  w  += 6
	add	W, Hack
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;        ADDLW   0x06 		;w  += 6
	mov	Hack, W
	mov	W, #$06	;w  += 6
	add	W, Hack
	sb	DC	;if w < 10
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  -0x06 		;  w  -= 6
	mov	Hack, W
	mov	W, #-$06	;  w  -= 6
	add	W, Hack

	snb	bin.4
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW   0x16 - 1 + 0x6
	mov	Hack, W
	mov	W, #$16 - 1 + $6
	add	W, Hack
	sb	DC
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  -0x06
	mov	Hack, W
	mov	W, #-$06
	add	W, Hack

	snb	bin.5
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  0x30
	mov	Hack, W
	mov	W, #$30
	add	W, Hack

	snb	bin.6
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  0x60
	mov	Hack, W
	mov	W, #$60
	add	W, Hack

	snb	bin.7
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  0x20
	mov	Hack, W
	mov	W, #$20
	add	W, Hack

;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;        ADDLW   0x60
	mov	Hack, W
	mov	W, #$60
	add	W, Hack
	rl	hundreds
	sb	hundreds.0
;*** WARNING: ADDLW was expanded in three instructions! Check if previous instruction is a skip instruction. 
;         ADDLW  -0x60
	mov	Hack, W
	mov	W, #-$60
	add	W, Hack

	mov	tens_and_ones, W
	snb	bin.7
	inc	hundreds