Searching \ for '[PIC]: NUmber crunching 48/24 equ 24 optimisations' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'NUmber crunching 48/24 equ 24 optimisations'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: NUmber crunching 48/24 equ 24 optimisations'
2000\10\26@111559 by o-8859-1?Q?K=FCbek_Tony?=

Hi, an small suggestion for
speeding up the 48/24 routine posted the other day.
If result is known to be (or most often) within 24 bits
then this alternative start snippet might save
24 loops to the expence of about 20 lines of code.

Here goes: ( only the startbit )


       ; Test for zero division
       MOVF    Divisor,W
       IORWF   Divisor+1,W
       IORWF   Divisor+2,W
       RETLW   0x00    ; divisor = zero, not possible to calculate
return with zero in w

       ; prepare used variables
       CLRF    Temp
       CLRF    Temp+1
       CLRF    Temp+2

       MOVLW   D'48'           ; initialize bit counter
       MOVWF   BitCount

       CLRC    ; clear carry at entry

       ; some test to shorten number of loops
       ; in division routine.
       ; Not required, but
       ; can save 24 loops when the result is known to
       ; fit into 24 bits
       ; if we have something in the top nibble
       ; of divisor we know that the result will
       ; always fit into 3 bytes and 24 loops can be skipped
       MOVF    Divisor,W       ; get msb of divisor
       ANDLW   0xF0            ; Mask out top four bits
       BZ      DIVIDE_LOOP_48by24      ; ok result larger than 24 bits
run full loop

       ; here carry MUST be cleared ( in this snippet performed above )

       ; we know that result will fit into 24 bits
       ; first divide counter with 2
       RRF     BitCount,F      ; i.e. bitcount = 24 ( note does not
affect carry )
       ; setup dividend and temp
       ; i.e move top three bytes of dividend into Temp
       MOVF    Dividend,W
       MOVWF   Temp
       MOVF    Dividend+1,W
       MOVWF   Temp+1
       MOVF    Dividend+2,W
       MOVWF   Temp+2
       ; move bottom three bytes in dividend into top three bytes
       MOVF    Dividend+3,W
       MOVWF   Dividend
       MOVF    Dividend+4,W
       MOVWF   Dividend+1
       MOVF    Dividend+5,W
       MOVWF   Dividend+2
       ; finally clear bottom three bytes ( which will be
       ; top three bytes in the result )
       CLRF    Dividend+3
       CLRF    Dividend+4
       CLRF    Dividend+5
the same as before but with Nicolai's improvements.


Tony Kübek, Flintab AB            

-- hint: The PICList is archived three different
ways.  See for details.

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