View Single Post
  #2   Spotlight this post!  
Unread 04-01-2008, 22:06
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: How does division work?

Quote:
Originally Posted by comphappy View Post
If you need the extra places the most efficient way to do it will be to bit shift the dividend, and remember that any time you need to do a calculation, you need to bit shift the result back. using bit shift instead of multiplying by something like 10 will save you a few clock cycles.

multiplication 8-bit by 8-bit method (if you multiply by an arbitrary value such as 10)
see here http://www.dcc.unicamp.br/~celio/mc4...los/mul8x8.asm

Program Memory : 14 locations
# of cycles : 71
RAM : 5 locations
That is a really big waist

bit shift method
c equivalent
x<<1;

can be done with the single asm command lrol (load and rotate left)
Noooooooo..... See, I too though I'd be clever and use fixed point math like this. But PIC's specification of ANSI C has an interesting quirk. All right shifts are treated as unsigned. So if you have a signed int (-500) that you right shift by one bit, you don't get -250. You get 32518. There are obviously ways to compensate like making sure all your values are positive by using offsets, etc. But don't just assume that >>1 is an innocent substitute for /2.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter