This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

XC 167: 2s complement fractional format

Hello,
I'm trying to use 2s complement fractional format in XC 167 a and I have following problem with multiplication:

 /*2s complement fractional format - multiplication test*/

#include <XC167.h>
#include <intrins.h>

signed short int a = 1024;  // = 0.03125
signed short int b = 1024;  // = 0.03125
signed short int c, x;

void main (void)
{
MCW = 0x0400;               //MP = 1, automatic shift 1 bit left

x = b * a;
c = MDH;

} 

The result c is 16d and I expect 32d (0.0009765625). Product after multiplication is not shifted one bit left.

Can anyone give me a rough idea how to use 2s complement fractional format?

I'm using uVision2 and C is recommended.

Thank you
Pavel

Parents
  • I wanted to shift to left by one 32-bit result of multiplication. It should be ensured by setting of MAC Control Word (MCW_MP=1). Then high order 16 bits (reg. MDH) of shifted 32-bit result should be desired result.

    It is the same like shifting to right by 15 and using low order 16 bits. But your expression is independent on hardware.

    Thank you very much.

Reply
  • I wanted to shift to left by one 32-bit result of multiplication. It should be ensured by setting of MAC Control Word (MCW_MP=1). Then high order 16 bits (reg. MDH) of shifted 32-bit result should be desired result.

    It is the same like shifting to right by 15 and using low order 16 bits. But your expression is independent on hardware.

    Thank you very much.

Children