Hello.
Can anyone explain to me why in this simple routine in BCD adjustment we need to add 3 and check for >7?
I don't reallly understand why I have to add 3...
Thank you
Can anyone explain to me why in this simple routine in BCD adjustment we need to add 3 and check for >7?
I don't reallly understand why I have to add 3...
Thank you
Code:
;***************************************************************************
; Bin2BCD16 - Converts a 16-bit binary number in TEMPH:TEMPL into a 3 byte packed
; BCD number in R0:R1:R2.
; R0 holds the 10 thousands digit
; R1 holds the hundreds and thousands digits
; R2 holds the ones and tens digits
;***************************************************************************
; Inputs: TEMPH, TEMPL (16-bit binary number)
; Outputs: R0, R1, R2 (5 digit BCD number)
; Used: COUNT
Bin2BCD16
bcf STATUS,C ; clear carry bit
movlw .16
movwf COUNT ; init bit counter
clrf R0 ; clear output
clrf R1 ; clear output
clrf R2 ; clear output
Loop16a2
rlcf TEMPL,F ; mult by 2, shift MSb to TEMPH
rlcf TEMPH,F ; mult by 2, shift MSb to R2
rlcf R2,F ; mult by 2, shift MSb to R1
rlcf R1,F ; mult by 2, shift MSb to R0
rlcf R0,F ; mult by 2, shift MSb to Carry
decfsz COUNT,F ; decrement bit counter
goto AdjDec2
return
AdjDec2
LFSR FSR0,R2
call AdjBCD2
LFSR FSR0,R1
call AdjBCD2
LFSR FSR0,R0
call AdjBCD2
goto Loop16a2
AdjBCD2
movlw 3
addwf INDF0,W ; W = 3 + Rn
movwf TEMP ; TEMP = 3+Rn
btfsc TEMP,3 ;
movwf INDF0 ; Rn=TEMP
movlw 30 ; decimal adjust?
addwf INDF0,W ; W=30+Rn
movwf TEMP ; TEMP=30+Rn
btfsc TEMP,7
movwf INDF0 ; Rn=TEMP
return