Switch statement problems with Codewarrior 5.0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switch statement problems with Codewarrior 5.0

2,247 Views
FC
Contributor III

Hello,

 

For switch statments with a lot of labels, the simulator does not select the correct label.  It produces a lot of exta instructions.  If a few labels are used, then it works fine.  Below is the sample code.  For example, if level = 4, the simulator selects 12.

 

Thansks

 

switch(DISPLevelCode)
  {
   
    case 1:     DISPGraphData = 0x03;
                   break;
    case 2:     DISPGraphData = 0x0F;
                   break;
    case 3:     DISPGraphData = 0x3F;
                   break;
    case 4:     DISPGraphData = 0xFF;
                   break;
    case 8:     DISPGraphData = 0x01;
                   break;
    case 9:     DISPGraphData = 0x07;
                   break;
    case 10:   DISPGraphData = 0x1F;
                   break;
    case 11:   DISPGraphData = 0x7F;
                   break;
    case 12:   DISPGraphData = 0xFF;
                  break;
    default:    DISPGraphData = 0x00;

Labels (1)
Tags (1)
0 Kudos
2 Replies

741 Views
bigmac
Specialist III

Hello,

 

I wonder if this is an issue of optimisation by the compiler, since the same action occurs for case 4 and case 12.  You could have equally written this code in the following form, and there would be no issue.

 

  case 4:

  case 12:

     DISPGraphData = 0xFF; break;

 

 Does the issue still occur if different values are assigned in each of the cases?

 

Regards,

Mac

 

741 Views
CompilerGuru
NXP Employee
NXP Employee

It's probably the branch tail merging optimization which combines the identical case entries.

Try with "-onb=t -onbt".

 

Daniel

 

BTW: Please always list which cpu you are targeting.