It's convenient when 8 bits of resolution is enough.
Try this one, you can shorten as necessary. It's for a 16F pic, but it should work with minor mods.
binX, binU, binH and binL are the 32 bit input field. temp is a temp field. The output fields are obvious.
; ; binary_to_bcd - convert 32bit unsigned binary value to 10 digits of BCD ;
binary_to_bcd
bcf STATUS, 0 ; clear the carry bit movlw .32 movwf count clrf billions_and_hundredmillions clrf tenmillions_and_millions clrf hundredthousands_and_tenthousands clrf thousands_and_hundreds clrf tens_and_ones loop32 rlf binL, F rlf binH, F rlf binU, F rlf binX, F rlf tens_and_ones, F rlf thousands_and_hundreds, F rlf hundredthousands_and_tenthousands, F rlf tenmillions_and_millions, F rlf billions_and_hundredmillions, F ; decfsz count, F goto adjDEC RETLW 0 ; adjDEC bcf STATUS, IRP
movlw tens_and_ones movwf FSR call adjBCD ; movlw thousands_and_hundreds movwf FSR call adjBCD ; movlw hundredthousands_and_tenthousands movwf FSR call adjBCD
movlw tenmillions_and_millions movwf FSR call adjBCD
movlw billions_and_hundredmillions movwf FSR call adjBCD ; goto loop32 ; adjBCD movlw 3 addwf INDF,W movwf temp btfsc temp,3 ; test if result > 7 movwf INDF movlw 0x30 addwf INDF,W movwf temp btfsc temp,7 ; test if result > 7 movwf INDF ; save as MSD RETLW 0
It may not cause this, but it can lead to other interesting "results".