This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

switch problem

C51 version 7.09

a = LEFT ;
switch (a)
{ case LEFT : subproA		  		      P1 = 0x01;
	      P1 = 0x01;
	      subproA				      break;
  case RIGHT : subproB		  		      P1 = 0x01;
	      P1 = 0x01;
	      subproB				      break;
  default : somethingjob;
}	  				   
There is incorrect excution flow.
This action should go first line of case LEFT and excuted all comment, but it doesn't. after it go to first line of case LEFT, thenn it jump to other place,where is second line of case RIGHT to excution.
And it is like not going to default place after all case comment.

  • You have provided an example which cannot be compiled. You have not provided the assembler listing for the code in question.

    Without more information, it's impossible for anyone to help you with this.

    Jon

  • "it is like not going to default place after all case comment"

    That is correct operation for a 'C' switch statement!

  • Have you looked at the generated assembly with and without optimization? The double assignment to P1 that is common to both branches of the case might be optimized into a single bit of code.

    (Since "subproA" and "subproB" are not syntactically correct C, it's obvious you've abstracted the actual code. So it's hard to tell exactly what's going on. Be sure you haven't omitted any details or inavertently corrected a problem in transforming the original structure to a post.)