Int2BCD10
;______________________________________________________________________________
;The actual BCD conversion loop
rlc r3 ;Shift oiver the LB
rlc r2 ;Now the HB
adc r1, r1 ;Multiply by two
da r1
adc r0, r0 ;HB too
da r0
djnz r4, Int2BCD10 ;All sixteen bits
;_____________________________________________________________________________
;Format and return the BCD
ld r2, 6(r15) ;Pointer to return array, usually 5(r15)
ld @r2, r0 ;Store the HB, 1000s
swap @r2 ;Reverse order
and @r2, #0FH ;Mask only lower nibble
inc r2 ;Next digit
ld @r2, r0 ;Store 100s
and @r2, #0FH ;Mask only lower nibble
inc r2 ;Now LB
ld @r2, r1 ;Store 10s
swap @r2 ;Other order
and @r2, #0FH ;Mask only lower nibble
inc r2 ;Point at 0nes
ld @r2, r1 ;store ones
and @r2, #0FH ;Mask only lower nibble