Searching \ for 'It never ends...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=never+ends
Search entire site for: 'It never ends...'.

Truncated match.
PICList Thread
'It never ends...'
1995\09\20@225339 by Andrew Warren

face
flavicon
face
Ok... Remember that stupid BCD-to-Binary converter I posted about a month ago?

Turns out that it has YET ANOTHER bug.  This really shouldn't surprise me, I
guess, since I wrote both previous versions while I was online and never even
assembled or tested them.

Normally, I wouldn't waste bandwidth endlessly reposting updated versions of a
routine like this, but I've heard from a few foolhardy souls who tell me
they're using it, so I feel a certain responsibility.

Anyway, this new bug was discovered by Bob Fehrenbach; it manifests itself
when THOU equals 0.  Fortunately, the fix is pretty trivial; just add a "SKPZ"
before the "DECF THOU", and add a "CLRC" after it.  The newest version of the
routine (which I STILL have neither assembled nor tested) follows:

;
; Four-Digit BCD to 2-Byte Binary Converter (version 3),
; written by Andy Warren.
;
; (C) 1995 Fast Forward Engineering.  All right reserved.
;
; Permission is hereby granted for any non-commercial use, so long as
; this copyright notice remains intact.
;
; Version 1 - First try.  Written at the ned of a 40-hour day.
; Version 2 - Got some sleep, found a bug in the "THOU = THOU*250/256"
;             section, and fixed it.
; Version 3 - Fixed the "What if THOU = 0?" bug discovered by Bob Fehrenbach.
;

      THOU   EQU     [any register]
      HUND   EQU     [any register]
      TENS   EQU     [any register]
      ONES   EQU     [any register]
      TEMP   EQU     [any register]

; Enter with four-digit BCD value in THOU, HUND, TENS, and ONES.
; Exits with 16-bit result in THOU (hi-byte) and HUND (lo-byte); TENS,
; ONES, and TEMP are scrambled.

BCD2BIN:

       CLRC                ;------------------------
       RLF     TENS,W      ;W = TENS*2.            ;
       MOVWF   TEMP        ;                       ;   By the way, this
       RLF     TEMP,W      ;W = TENS*4.            ;-- is a pretty good
       ADDWF   TENS        ;TENS = TENS*5.         ;   2-digit BCD to
       RLF     TENS        ;TENS = TENS*10.        ;   binary converter
       ADDWF   ONES        ;ONES = TENS*10 + ONES. ;   by itself...
                           ;------------------------

       RLF     THOU,W      ;W = THOU*2 (CLRC not necessary here).
       ADDWF   THOU,W      ;W = THOU*3.
       MOVWF   TEMP        ;
       RLF     TEMP,W      ;W = THOU*6.
       CLRF    TEMP        ;
       SUBWF   TEMP        ;
       SKPZ                    ;
       DECF    THOU        ;THOU:TEMP = THOU*250 / 256.
       CLRC                ;
       RLF     TEMP        ;
       RLF     THOU        ;THOU:TEMP = THOU*500 / 256.
       RLF     TEMP        ;
       RLF     THOU        ;THOU:TEMP = THOU*1000 / 256.

       RLF     HUND,W      ;W = HUND*2.
       ADDWF   HUND,W      ;W = HUND*3.
       MOVWF   TENS        ;TENS = HUND*3.
       RLF     TENS        ;TENS = HUND*6.
       RLF     TENS        ;TENS = HUND*12.
       RLF     TENS,W      ;W = HUND*24.
       ADDWF   HUND        ;HUND = HUND*25.
       CLRF    TENS        ;
       RLF     HUND        ;
       RLF     TENS        ;TENS:HUND = HUND*50.
       RLF     HUND        ;
       RLF     TENS        ;TENS:HUND = HUND*100.

       MOVF    ONES,W      ;
       ADDWF   TEMP,W      ;
       SKPNC               ;
       INCF    TENS        ;
       ADDWF   HUND        ;HUND = LO-BYTE OF RESULT.
       SKPNC               ;
       INCF    TENS        ;
       MOVF    TENS,W      ;
       ADDWF   THOU        ;THOU = HI-BYTE OF RESULT.

DONE:
                           ;THOU:HUND = 1000*THOU + 100*HUND
                           ;            + 10 * TENS + ONES.

-Andy

--
Andrew Warren - spam_OUTfastfwdTakeThisOuTspamix.netcom.com
Fast Forward Engineering, Vista, California

More... (looser matching)
- Last day of these posts
- In 1995 , 1996 only
- Today
- New search...