Hi,
I found a problem in the generated code for the following scenario: when calling the labs() function for an 8-bit signed integer and the result is stored in an unsigened 8-bit integer, the sign extension step is missing from the generated assembly code, which in fact calls the abs() function. This issue is causing a larger application to produce incorrect results.
In order to reproduce it, compile this simplified example code and look at the assembly code for the function call:
#include <stdlib.h>
struct _fxp_heap {
signed char iVal;
unsigned char iAbs, iAbsExpected;
} fxp_heap;
struct _fxp_heap *pfxp_heap = &fxp_heap;
int main()
{
pfxp_heap->iVal = (signed char)-10;
pfxp_heap->iAbsExpected = (unsigned char)10;
pfxp_heap->iAbs = labs(pfxp_heap->iVal);
if (pfxp_heap->iAbs != pfxp_heap->iAbsExpected)
return 1;
return 0;
}
I am using the latest version (3.2.3) of the CCS compiler for msp430.
If it is a compiler problem, is it possible to fix?
Thanks,
Alpar