Quote:
Originally Posted by comphappy
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.