[an error occurred while processing this directive]
|
Вот такой, например:
;-----------------------------------------------------------------
; Bin(fbinH,fbinM,fbinL) --> BCD(tBCD3,tBCD2,tBCD1,tBCD0).
; uses: r0..r3, r16..r18,r20,r21,r30,r31. T=751..768t ?
; not for AT90Sxx0x
;-----------------------------------------------------------------
NAME bin2bcd6
#include iom16.h
PUBLIC bin2bcd6
RSEG CODE
AtBCD0 equ 0 ;address of tBCD0
AtBCD3 equ 3 ;address of tBCD3
#define tBCD0 r0 ;BCD value digits 1 and 0
#define tBCD1 r1 ;BCD value digits 3 and 2
#define tBCD2 r2 ;BCD value digits 5 and 4
#define tBCD3 r3 ;BCD value digits 7 and 6
#define fbinL r16 ;binary value Low byte
#define fbinM r17 ;binary value Medium byte
#define fbinH r18 ;binary value High byte
#define ZH r31
#define ZL r30
#define cnt16a r20 ;loop counter ???
#define tmp16a r21 ;temporary value ???
bin2bcd6:
ldi r20, 24 ;Init loop counter
clr tBCD3 ;clear result (4 bytes)
clr tBCD2
clr tBCD1
clr tBCD0
clr ZH ;clear ZH (not needed for AT90Sxx0x)
bBCDx_1a: lsl fbinL ;shift input value
rol fbinM ;through all bytes
rol fbinH
rol tBCD0
rol tBCD1
rol tBCD2
rol tBCD3
dec r20 ;decrement loop counter
brne bBCDx_2a ;if counter not zero
mov r16,tBCD0
mov r17,tBCD1
mov r18,tBCD2
mov r19,tBCD3
ret ; return
bBCDx_2a: ldi ZL, AtBCD3+1 ;Z points to result MSB + 1
bBCDx_3a: 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,AtBCD0 ;done all?
brne bBCDx_3a ;loop again if not
rjmp bBCDx_1a
END