 |
|
 |
RENESAS TOOL NEWS on March 1, 2004: RSO-M3T-NC30WA_1-040301D
A Note on Using C Compiler M3T-NC30WA
--On an OR Operation Between a Variable and a Constant--
|
Please take note of the following problem in using C compiler (with an assembler and integrated development environment)
M3T-NC30WA for the M16C/60, M16C/30, M16C/Tiny, M16C/20, M16C/10, and R8C/Tiny series MCUs:
- On an OR operation between a variable and a constant
- Versions Concerned
M3T-NC30WA V.2.00 Release 1 through V.5.20 Release 1
- Description
Performing an OR operation between a variable of type unsigned or signed long and a constant of powers of 2 may generate incorrect code.
- Conditions
This problem occurs if the following four conditions are satisfied:
| (1) |
An OR operation between variable A and a constant of powers of 2 is performed.
|
| (2) |
The type of variable A is unsigned or signed long.
|
| (3) |
Variable A is declared with the volatile qualifier.
|
| (4) |
The result of the operation (1) is assigned to variable B, which satisfies the following conditions:
a. It is an auto variable.
b. It is declared without the volatile qualifier.
c. Its address is either of the following:
* the address of register FB - 17 or earlier
* the address of register FB + 16 or later
|
- Example
--------------------------------------------------------
volatile long gl; /* Conditions (2) and (3) */
void func(void)
{
long bl[6]; /* Condition (4) */
bl[0] = gl | 0x000001L; /* Conditions (1) and (4) */
...
}
--------------------------------------------------------
- Workaround
This problem can be circumvented by going through the following steps:
| (1) |
Define temporary variable C of type signed or unsigned long.
|
| (2) |
Assign to the variable in (1) the constant of powers of 2 between which and variable A an OR operation would be done.
|
| (3) |
Perform the OR operation between variables A and C.
--------------------------------------------------------
volatile long gl;
void func(void)
{
long bl[6];
long tmp; /* Constant C */
tmp = 0x000001L;
bl[0] = gl | tmp;
...
}
--------------------------------------------------------
|
- Schedule of Fixing the Problem
We plan to fix this problem in our next release of the product.
|
 |