Ok, let's see... We'll start with 100 value1: 100 value2: value1: 50 value2: 50 value1: 12 value2: 50 Result = value1 - value2 = -38 The reason this doesn't work is that you cannot add and subtract divisors like you can add and subtract multipliers. The equivilant statement is: x/8 - x/2 which then becomes x/8 - 4x/8 which is equal to -3x/8 The result of which is -3/8 of the original number. If you add them instead of subtracting, you get 5/8 of the original number. The true divide by ten MUST include a factor of 5 in the divisor: x/(2*5) Since that cannot be duplicated in rotations (divisions or multiplications by two) then the PIC can only approximate such a result with rotations. As others have said, the approximations involve adding together smaller divisions of 2: x/10 is larger than x/16, so add x/16 to the result. The remainder is x/26.66. x/26 is larger than x/32, so add x/32 to the result. The remainder is x/160 x/160 is larger than x/256, so add x/256 to the result. The remainder is x/426.66 etc As you can see, with just the above three divisions you get 25x/256, which is fairly close to 1/10. You can compute the exact error by subtracting the approximate from the ideal, then dividing by the ideal. In this case, those three terms give you a 2.3% error. You may be able to come closer to the goal in fewer terms by doing 9/10 of x, then subtracting that from x. -Adam Andrew Kieran wrote: >There are many solutions, but two in particular that I would >consider: > >1) >o starting with number to be divided in 'value1' >o Shift right, store result in 'value1' and 'value2' >o shift right, 'value1' two more times, storing result in >'value1' >o subtract 'value2' from 'value1' >o The result is the original 'value1' divided by 10 > >This works likes this: >rrf - divides by two, store in 'value2' >rrf - now divided by four >rrf - now divided by eight >subtract 'value2' - now divided by ten > >Note also that the state of the carry flag after the last shift >can be used to determne whether to round-up the result > >2) >Alterately, I would consider using one of the general purpose >division routines from the PICLIST. You should have one for >your code library anyway. So unless you're code space is really >tight and you don't need to do any other division, I'd use the >general purpose routine rather than this specialized divide by >ten approach. > >That's my $0.02 > >Andrew > > > > >________________________________________________ >Get your own "800" number >Voicemail, fax, email, and a lot more >http://www.ureach.com/reg/tag > > >---- On , Phil (phil@SPIDERWEB.COM.AU) wrote: > > > >>Hello everyone, >> >>I'm looking for a divide by 10 routine. The number that I want >> >> >to divide is an > > >>8 bit number but I will very likely need to divide 10 bit >> >> >numbers by ten as > > >>well. >> >>While playing with micro processors during the mid 70s I >> >> >remember that > > >>dividing by ten involved a shift right and an add instruction >> >> >but I cannot > > >>remember the sequence. >> >>A web search has revealed many 16 bit division routines but >> >> >they look more > > >>complex than I remember for a simple divide by 10. >> >>Again, can someone help? >> >>-- >>Regards, >>Phil. >> >>-- >>http://www.piclist.com hint: The list server can filter out >> >> >subtopics > > >>(like ads or off topics) for you. See >> >> >http://www.piclist.com/#topics > > >> >> > >-- >http://www.piclist.com hint: The list server can filter out subtopics >(like ads or off topics) for you. See http://www.piclist.com/#topics > > > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics