Hello Jon & PIC.ers, >Date: Sun, 2 Feb 2003 22:35:44 -0800 >From: "Jon M (Mike) Jones" >Subject: [PIC]: Binary to Packed BCD Conversion Problem > >I was searching for a binary to BCD conversion routine and found this: >http://www.piclist.org/techref/postbot.asp?by=3Dtime&id=3Dpiclist/2002/12= >/24/164925a >from Bob Ammerman. It appeared to be just what I was looking for but it >'seems' to have a problem. Can anyone tell me what is missing/wrong with = >this macro > or suggest where I may be going wrong with its use?=20 > I have been using the following routine successfully for some years. It was adapted from an original algorithm by Bob Fehrenbach, to meet my internal editing norms. The macro `movlf' moves literal to freg. ************************************************ BIN2BCD ;Date: Mon, 16 Mar 1998 14:18:12 -0600 ;From: Bob Fehrenbach ;Subject: Re: 32 bits binary to BCD convert? ;>Does anyone know how to convert 32 bits binary to BCD format? ;There probably faster routines but this should do the job. ; Binary - BCD 32 bits ; Input in buff_4 buff_3 buff_2 buff_1 with MSByte buff_4 ; ; Converts to *packed* bcd in temp_a(ms), temp_b, temp_c, ;temp_d, temp_e with the most sig in temp_a. ; Handles full range: ff ff ff ff -> 4,294,967,296 ; Also uses temp_f and count. ; 2940 cycles including call and return. ; bcf status, c movlf 32, scratch_lo clrf temp_a clrf temp_b clrf temp_c clrf temp_d clrf temp_e bin2bcd_loop: rlf buff_1, same rlf buff_2, same rlf buff_3, same rlf buff_4, same rlf temp_e, same rlf temp_d, same rlf temp_c, same rlf temp_b, same rlf temp_a, same decfsz scratch_lo, same goto adj_dec goto done adj_dec: movlf temp_e, fsr call adj_bcd movlf temp_d, fsr call adj_bcd movlf temp_c, fsr call adj_bcd movlf temp_b, fsr call adj_bcd movlf temp_a, fsr call adj_bcd goto bin2bcd_loop adj_bcd: movlw h'3' addwf indf, w movwf temp_f btfsC temp_f, 3 movwf indf movlw h'30' addwf indf, w movwf temp_f btfsC temp_f, 7 movwf indf return done: return ************************************************ best regards, John eMail from the desk of John Sanderson. JS Controls, PO Box 1887, Boksburg 1460, Rep. of S. Africa. Tel / Voice / Fax : 011 893 4154 email : jsand @pixie.co.za Cell : 082 741 6275 Manufacturer & Purveyor of laboratory force testing apparatus and related products & services. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body