I still (even though PICs are more powerful nowadays) avoid floating-point calcs. If I need say 2 decimal points, I multiply by 100 earlier, then do the division and insert the decimal point as appropriate.

> I am trying to find some good 8 and 16 bit division routines for mid range
> PICs. Most of the app notes I have found give algorithms which result in
> a quotient and remainder.
>
> However in my case the divisor is always greater than the dividend so I
> want a result that is conceptually between 0 and nearly 1 with an implied
> binary point to the left.
>
> I have written my own routines but I suspect that they are far from optimum.
> __________________________________________
> David C Brown
> 43 Bings Road
> Whaley Bridge
> High Peak Phone: 01663 733236
> Derbyshire eMail: .....dcb.homeKILLspam@spam@gmail.com
> SK23 7ND web: http://www.bings-knowle.co.uk/dcb
> <http://www.jb.man.ac.uk/~dcb>
>
>
>
> *Sent from my etch-a-sketch*

> I am trying to find some good 8 and 16 bit division routines for mid range
> PICs. Most of the app notes I have found give algorithms which result in
> a quotient and remainder.
>
> However in my case the divisor is always greater than the dividend so I
> want a result that is conceptually between 0 and nearly 1 with an implied
> binary point to the left.
>
> I have written my own routines but I suspect that they are far from optimum.

> in my case the divisor is always greater than the dividend so I
> want a result that is conceptually between 0 and nearly 1 with an implied
> binary point to the left.

It’s equivalent to multiplying your dividend by 256 or 65536 and using 16/32bit division, right? Except that you know you’ll run out of 1 bits comparatively early, and might be able to optimize away the extra registers. Hmm. An interesting problem!

Perhaps I have been selling myself short ! Whist I thank you for your
suggestions at the risk of sounding sarcastic which is not my intent, there
is nothing there that I couldn't get from my 1967 university textbook.. Or
from experienced engineers in my first job at International Computers Ltd
in 1969.

The basic non restoring algorithm must have been developed by Turing or
Wilkes or one of there contemporaries back in the fifties. For interest,
or not, This my take on it. - 55 memories, 2 working registers, worst case
156 instructions. Please criticise to your hearts content

..;=============================================================================;
; This Routine divides DIVIDEND BY DIVISOR for numbers less than 1. That is
;
; numbers with an implied binary point aat the extreme left. The divisor
;
; must be greater than the dividend so thaat the quotient remains less than
1 ;
; ENTRY: Dividend in REGA. Divisor in REGB
;
; EXIT: Quotient in REGAX,REGA W is 0
;
; (IF Dividend > Divisor W is -1 and REGAX,REGA = REGA -REGB)
;
; USES: REGQ, DCNT
;
;=============================================================================;

> Perhaps I have been selling myself short ! Whist I thank you for your
> suggestions at the risk of sounding sarcastic which is not my intent, there
> is nothing there that I couldn't get from my 1967 university textbook.. Or
> from experienced engineers in my first job at International Computers Ltd
> in 1969.
>
> The basic non restoring algorithm must have been developed by Turing or
> Wilkes or one of there contemporaries back in the fifties. For interest,
> or not, This my take on it. - 55 memories, 2 working registers, worst case
> 156 instructions. Please criticise to your hearts content

Next time how about you cut straight to the chase, present your code and say something like "hey does anybody know how to do division better than this".

And here's a tip for you, if you think you might be sounding sarcastic (and in this case it comes across in spades) then just do yourself a favour and leave the comment out.

I didn't have solid code at the time I first asked the question and didn't
want to spend hours testing if someone had a better algorithm.

If I had taken your advice and to leave the comment out because of fear of
sarcasm I would have failed to make the wonderful point about how clever
those early computer pioneers were.
Thank you for your correction to my grammar which you are well aware was
a typographical rather than a grammatical error.

>
> Next time how about you cut straight to the chase, present your code and
> say something like "hey does anybody know how to do division better than
> this".
>
> And here's a tip for you, if you think you might be sounding sarcastic
> (and in this case it comes across in spades) then just do yourself a
> favour and leave the comment out.
>
> BTW "there contemporaries" should be "their contemporaries"
>
> Regards
> Sergio Masci
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>

> The basic non restoring algorithm must have been developed by Turing or
> Wilkes or one of there contemporaries back in the fifties. For interest,
> or not, This my take on it. - 55 memories, 2 working registers, worst case
> 156 instructions. Please criticise to your hearts content