 |
|
 |
RENESAS TOOL NEWS on February 1, 2005: RSO-M3T-NC30WA_3-050201D
A Note on Using C-Compiler Package M3T-NC30WA
--On Using switch Statements--
|
Please take note of the following problem in using the M3T-NC30WA
C-compiler package which is used for the M16C/60, M16C/30, M16C/20, M16C/10,
M16C/Tiny, and R8C/Tiny series of MCUs:
- On using switch statements
- Versions Concerned
M3T-NC30WA V.1.00 Release 1 through V.5.00 Release 1, and V.5.10 Release 1 through V.5.30 Release 1
- Description
If the controlling expression in a switch statement is of type signed char,
code of jumps to correct case labels may not be generated.
- 2.1 Conditions
- This problem occurs if the following conditions are all satisfied:
| (1) | The controlling expression in a switch statement is of type signed char.
|
| (2) | The maximum and minimum values of case labels are different in signs.
|
| (3) | Twelve or more case labels exist in the switch statement in (1).
|
| (4) | After compilation, an address table of jump destinations and indirect jumps using
this table are generated in assembly-language code. |
- 2.2 Examples
C-language source code:
-------------------------------------------------------------
signed char sc;
void func(void)
{
switch (sc) {
case -8:
. . . . . . . . . . . . .
case 1:
. . . . . . . . . . . . .
-------------------------------------------------------------
Assembly-language code generated by the above source file:
-------------------------------------------------------------
mov.b _sc:R0L
mov.b R0L,A0
sub.b #0f8H,A0
cmp.b #11H,A0
jnc M1
mov.w #10H,A0
M1:
sha.w #1,A0
S1:
jmpi.w L35[A0]
L35:
.word L19-S1&0ffffH
.word L21-S1&0ffffH
.word L23-S1&0ffffH
.word L25-S1&0ffffH
. . . . . . . . . . . . . . . .
-------------------------------------------------------------
- Workaround
Convert the controlling expression of type signed char in a switch statement to
that of type signed int using the cast operator.
Example:
-------------------------------------------------------------
signed char sc;
void func(void)
{
switch((signed int)sc) {
case 0:
. . . . . . . . . . . . . . . . .
-------------------------------------------------------------
- Schedule of Fixing the Problem
This problem has already been fixed in the M3T-NC30WA V.5.30 Release 02 and later.
|
 |