;
; Jake's modified 13+ bit 0000..9999 bin-to-dec algorithm
;
; input: binh:binl -> 0x0000..0x270F (0..9999)
; output: thou -> 0..9
; huns -> 0..9
; tens -> 0..9
; ones -> 0..9
;
; 19 words, 4 or 5 variables, 14..8330 cycles (Mike, K8LH)
;
radix dec
clrf thou ;
movlw -10 ; wreg = -10
resHuns movwf huns ; set huns = -10
resTens movwf tens ; set tens = -10
div10z addwf binl,F ; binl = binl - 10, borrow?
skpc ; no, skip, else
decf binh,F ; decrement hi byte
btfsc binh,7 ; negative? no, skip, else
goto b2dwrap ; wrap up (borrow/underflow)
incfsz tens,F ; tens overflow? yes, skip, else
goto div10z ; loop
incfsz huns,F ; huns overflow? yes, skip, else
goto resTens ; reset 'tens' & loop
incf thou,F ; bump 'thou'
goto resHuns ; reset 'huns' & 'tens' & loop
b2dwrap subwf huns,F ; fix huns
subwf tens,F ; fix tens
subwf binl,W ; fix ones
movwf ones ;