Пробуйте если мне неизменяет память это подправленый исходник аппнота
делалась давно - извиняюсь за корявость
Код
;**************************************************
; in temp4 -temp3-temp2-temp
; входное значение не более 99 999 999 (dec)
; out temp8-temp7-temp6-temp5
; time cpu = 1760 cycle
.equ _AtBCD5 =2;address of tBCD0
.equ _AtBCD7 =5;address of tBCD1
bin2BCD32:
pushz
push r20
push r21
ldi r20,32;Init loop counter
clr temp8
clr temp7;clear result (3 bytes)
clr temp6
clr temp5
clr ZH;clear ZH (not needed for AT90Sxx0x)
_bBCDx_1:
lsl TEMP;shift input value
rol TEMP2;through all bytes
rol temp3
rol temp4
rol temp5;
rol temp6
rol temp7
rol temp8
dec r20;decrement loop counter
brne _bBCDx_2;if counter not zero
pop r21
pop r20
popz
ret; return
_bBCDx_2:
ldi zl,_AtBCD7+1;Z points to result MSB + 1
_bBCDx_3:
ld r21,-Z;get (Z) with pre-decrement
subi r21,-$03;add 0x03
sbrc r21,3;if bit 3 not clear
st Z,r21; store back
ld r21,Z;get (Z)
subi r21,-$30;add 0x30
sbrc r21,7;if bit 7 not clear
st Z,r21; store back
cpi ZL,_AtBCD5;done all three?
brne _bBCDx_3;loop again if not
rjmp _bBCDx_1