Other Parts Discussed in Thread: TEST2
Try the following simple test.
CCS version = 4.1.3.00038
Target = F28035
// Main.c
#define a 0x1<<12
#define aa 0x1000
#define b 0x100
#define bb 0x111
int c = 0x2000;
long x;
void Test1 (void);
void Test1b (void);
void Test2 (void);
void Test3 (void);
void main (void)
{
Test1();
Test1b();
Test2();
Test3();
}
/* x = (b * c) / a
* x = (0x100 * 0x2000) / 0x1000
* x = 0x200000 / 0x1000
* x = 0x200
*/
void Test1 (void)
{
x = (long)((long)b * (long)c) / (long)a;
//x = 0x0 << WRONG!
//(Final Shift is wrong calculated)
}
void Test1b (void)
{
x = (long)((long)bb * (long)c) / (long)a;
//x = 0x22000000 << WRONG!
}
void Test2 (void)
{
long l;
l = (long)a;
x = (long)((long)b * (long)c) / l;
// x = 0x200 << Ok
}
void Test3 (void)
{
x = (long)((long)b * (long)c) / (long)aa;
// x = 0x200 << Ok
}