Searching \ for 'PICLIST Digest - 31 Aug 1997 to 1 Sep 1997' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'PICLIST Digest - 31 Aug 1997 to 1 Sep 1997'.

Truncated match.
PICList Thread
'PICLIST Digest - 31 Aug 1997 to 1 Sep 1997'
1997\09\05@024338 by Andy Shaw

flavicon
face
Hi Folks,
Does anyone out there have any code for a reasonably
fast divide by 10 routine. I'm just looking for a rounded
up 8 bit signed value as the result I don't need the
remainder.

Thanks in advance

Andy

1997\09\05@024338 by Andy Shaw

flavicon
face
Hi Folks,
Does anyone out there have any code for a reasonably
fast divide by 10 routine. I'm just looking for a rounded
up 8 bit signed value as the result I don't need the
remainder.

Thanks in advance

Andy

1997\09\05@102323 by Bob Fehrenbach

picon face
Andy Shaw <spam_OUTandy.shawTakeThisOuTspamVIRGIN.NET> wrote:
>Hi Folks,
>Does anyone out there have any code for a reasonably
>fast divide by 10 routine. I'm just looking for a rounded
>up 8 bit signed value as the result I don't need the
>remainder.

It's not clear how large your dividend is, but if it is a
single byte, take a look at this from Andy Warren.

(Posting this for Andy W in case he is taking a nap.)

Note that this is unsigned arithmetic.


; 8-Bit Divide.  Written by Andy Warren.
;
; Copyright (C) 1994 Fast Forward Engineering.  All rights reserved.
; Permission is hereby granted for any non-commercial use,
; so long as this copyright notice remains intact.
;
; Enter with Dividend in DIVIDEND, divisor in DIVISOR.
;
; Exits with quotient in QUOTIENT and remainder in REMAINDER, DIVIDEND
; scrambled, DIVISOR unchanged, carry-flag set.
; It takes about 80 cycles.

DIVIDE  MOVLW   1
       MOVWF   QUOTIENT

       CLRF    REMAINDER

LOOP    RLF     DIVIDEND
       RLF     REMAINDER

       MOVF    DIVISOR,W
       SUBWF   REMAINDER,W
       SKPNC

       MOVWF   REMAINDER

       RLF     QUOTIENT
       BNC     LOOP



--
Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam@spam@execpc.com

1997\09\05@115906 by Dmitry Kiryashov

flavicon
face
> Andy Shaw <andy.shawspamKILLspamVIRGIN.NET> wrote:
> >Hi Folks,
> >Does anyone out there have any code for a reasonably
> >fast divide by 10 routine. I'm just looking for a rounded
> >up 8 bit signed value as the result I don't need the
> >remainder.



X / 10 = X * 1/10       Is this right ? ;)

1/10 = (1/16 + 1/32) + (1/256 + 1/512) + ....

1/16 + 1/32 + 1/256 =  0,09765625 (-0,0234375%)

( 1 + 1/2 + 1/16 ) / 16 ;

;code
;initial var X
;result var Y

;+1/2
       clrc
       rrf     X,W
       movwf   Y

;+1/16
       swapf   X,W
       andlw   0xF
       addwf   Y,F

;+1
       movfw   X
       addwf   Y,F

;/16
       swapf   Y,W
       andlw   0xF

       skpnc
       addlw   0x10
       movwf   Y
;
; Caution: this code is not tested !!!


I think there are way to shrink this code .

WBR Dmitry.

1997\09\05@151703 by Bob Fehrenbach

picon face
Dmitry Kiryashov <.....zewsKILLspamspam.....AHA.RU> wrote:
>> Andy Shaw <EraseMEandy.shawspam_OUTspamTakeThisOuTVIRGIN.NET> wrote:
>> >Does anyone out there have any code for a reasonably
>> >fast divide by 10 routine.



  Dmitry's creative solution with a suggestion:

>;+1/2
>        clrc
>        rrf     X,W
>        movwf   Y
>
>;+1/16
>        swapf   X,W
>        andlw   0xF
>        addwf   Y,F

                    ; ***  New code inserted  ***

        swapf   X,W    ;  1/16 + 1/16:  improves round off
        andlw   0xF    ;
        addwf   Y,F    ;


{Quote hidden}

--
Bob Fehrenbach    Wauwatosa, WI     bfehrenbspamspam_OUTexecpc.com

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