ON 20040518@2:16:29 PM at page: http://www.piclist.com/techref/microchip/math/radix/bp2b-2d8b.htm#38125.5947800926 Silvan Minghetti[SM-bluewin-9A7] Code:
<pre>
; ==========================================================
; From: Scott Dattalo
;
; This version saves one cycle.
;
swapf bcd, W
andlw 0x0F ; W=tens
movwf temp
addwf temp, W ; W=2*tens
addwf temp, F ; temp=3*tens (note carry is cleared)
rlf temp, W ; W=6*tens
subwf bcd, W ; W = 16*tens+ones - 6*tens
; ==========================================================
; From: Silvan Minghetti
;
; Does not require an additional temp register, but trashes
; the content of the bcd register.
;
; Expects bcd value in 'bcd', returns binary value in WREG.
; To return the binary value in 'bcd', change the last line
; to subwf bcd, F
;
swapf bcd, F
rlf bcd, W
andlw b'00011110' ; WREG = tens * 2
swapf bcd, F
subwf bcd, F ; bcd = (tens * 16) - (tens * 2) + ones
subwf bcd, F ; bcd = (tens * 14) - (tens * 2) + ones
subwf bcd, W ; WREG = (tens * 12) - (tens * 2) + ones
; ==========================================================
; From: Scott Dattalo
;
; The upper method adapted for the PIC18 Family, saves one
; more cycle.
;
swapf bcd, W
andlw 0x0F ; W= tens
rlncf WREG, W ; W= 2*tens
subwf bcd, F ; 16*tens + ones - 2*tens
subwf bcd, F ; 14*tens + ones - 2*tens
subwf bcd, W ; 12*tens + ones - 2*tens
</pre>
ON 20040519@11:53:04 AM at page:
http://www.piclist.com/techref/microchip/math/radix/bp2b-2d8b.htm#
James Newton[JMN-EFP-786] edited the page. Difference:
http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\radix\bp2b-2d8b.htm&version=1