|
самый быстрый конвертер, который мне удалось найти. В данном случае контроллер PIC, если нет желания вникать в алгоритм преобразования, то можно асм тупо перенести на другую платформу.
Разрядность можно наращивать до ***, при этом время на преобразование сильно возрастает.
b2bcd3 movlw 0x33
E-mail:
info@telesys.ru
;******************************************************************
; Convert 32-bit binary number at
; at
; adjust; Modified Microchip AN526 for 32-bits.
; 2.25 mS
;******************************************************************
b2bcd movlw .32 ; 32-bits
movwf ii ; make cycle counter
clrf bcd ; clear result area (high bit)
clrf bcd+1
clrf bcd+2
clrf bcd+3
clrf bcd+4 ; low
b2bcd2 movlw bcd ; make pointer
movwf fsr
movlw .5
movwf cnt
; Mike's routine:
addwf indf,f ; add to both nybbles
btfsc indf,3 ; test if low result > 7
andlw 0xf0 ; low result >7 so take the 3 out
btfsc indf,7 ; test if high result > 7
andlw 0x0f ; high result > 7 so ok
subwf indf,f ; any results <= 7, subtract back
incf fsr,f ; point to next
decfsz cnt,f
goto b2bcd3
rlf bin+3,f ; get another bit
rlf bin+2,f
rlf bin+1,f
rlf bin+0,f ; high
rlf bcd+4,f ; put it into bcd
rlf bcd+3,f
rlf bcd+2,f
rlf bcd+1,f
rlf bcd+0,f ; high
decfsz ii,f ; all done?
goto b2bcd2 ; no, loop
return ; yes
Ответы