I want to multiply two fixed point numbers. After the multiplication I have to shift the result so that the binary point is correct. Example: int a; The multiplication a*b produces a long int value in the MD register. After the shift operation the int result (the lower byte) should be stored in c. |
|
Read-Only
Author
Andrew Neil Posted
22-Oct-2003 09:34 GMT Toolset
C166 |
RE: Fixed-point multiplication
I don't know the '166, but I suspect this is a 'C' issue rather than a processor issue. You could look up the promotion rules in K&R, or you could just try experimenting with casting a, b, and/or the product to long. |
Read-Only
Author
Mike Kleshov Posted
22-Oct-2003 09:56 GMT Toolset
C166 |
RE: Fixed-point multiplication
As Andrew said, this is a C issue. Take your favourite book on C and read about types and expressions. There are a few pitfalls there. - mike |
Read-Only
Author
Bruno Büsser Posted
22-Oct-2003 10:45 GMT Toolset
C166 |
RE: Fixed-point multiplication
That's it! The product a*b is stored as 32 bit value in MD register, then the MD register value is arithmetic shifted right by 10 and the lower 16 bits stored in c. |
http://www.keil.com/forum/3549/