 |
|
 |
MAEC TOOL NEWS:
MAECT-M3T-NC30WA-020316D
A Note on C Compiler M3T-NC30WA V.5.00 Release 1
|
Please take note of the following problem in using C compiler (with an assembler and integrated development environment) M3T-NC30WA V.5.00 Release 1 for the M16C/60, M16C/20, and M16C/10 series MCUs.
- On compiling conditional expressions in selection and iteration statements
- Description
When compiling any conditional expression, no "cmp" instruction may be generated or an incorrect "cmp" instruction (such as comparing a register not with another one but with itself) be generated. So, the compiled program may not perform the correct comparison.
- Conditions
- This problem occurs if the following nine conditions are satisfied:
- (1) A conditional expression contains a variable each in the left and right terms.
- (2) The type of each variable in the above conditional expression is any of the following:
- unsigned char
- unsigned int
- unsigned short
|
- signed char
- signed int
- signed short
|
- (3) Either the variable in the left term or the one in the right term in the above conditional expression is an auto variable or an argument to a function.
- (4) In the program statements exists an expression that contains a variable appearing in the conditional expression.
- (5) The expression in (4) is assigned to the same variable that appears in the left or right term of the conditional expression.
- (6) The right term of the expression in (4) contains the subexpression that is common to the conditional expression.
- (7) The subexpression in (6) is assigned to a register.
To see whether the result of operation of the subexpression is assigned to a register or not, check the code generated by the compiler.
- (8) During the steps from evaluating the conditional expression in (1) to performing the operation of the expression in (4), both the variables in the left and right terms of the conditional expression remain unchanged.
- (9) More than one optimizing option is selected out of -OR, -OS, -O, and -O[3-5].
- Examples
-----------------------------------------------------------------------
int gi,gi2;
short arr[10];
/* Example 1 */
int func1(int vi) {
if(vi < (gi + 1)){ /* Conditions (1), (2), and (3) */
gi2 = gi;
vi = gi + 1; /* Conditions (4), (5), (6), (7), and (8) */
}
return vi;
}
/* Example 2 */
int func2(int vi)
{
if(vi < (gi2 + 1)){ /* Conditions (1), (2), and (3) */
gi2++;
}else{
vi = gi2 + 1; /* Conditions (4), (5), (6), (7), and (8) */
}
return vi;
}
/* Example 3 */
int func3(void)
{
char a;
short b;
:
:
if( arr[b] > (short)a){ /* Conditions (1), (2), and (3) */
b = a; /* Conditions (4), (5), (6), and (8) */
:
}
}
-----------------------------------------------------------------------
- Workaround
Describe a dummy asm function immediately before the program statements.
-----------------------------------------------------------------------
/* Example 1 */
int func1(int vi)
{
if(vi < (gi + 1)){
asm(); /* A dummy asm function added */
gi2 = gi;
vi = gi + 1;
}
return vi;
}
/* Example 2 */
int func2(int vi)
{
if(vi < (gi2 + 1)){
asm(); /* A dummy asm function added */
gi2++;
}else{
vi = gi2 + 1;
}
return vi;
}
/* Example 3 */
int func3(void)
{
char a;
short b;
:
:
if( arr[b] > (short)a){
asm(); /* A dummy asm function added */
b = a;
:
}
}
-----------------------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release.
|
 |