Quantcast
Channel: Tools
Viewing all articles
Browse latest Browse all 91752

Forum Post: RE: CCS5.5 compiler bug or there is something I don't understand

$
0
0

[quote user="Hubert Huang"]60               for(j = 0; j < 6; j++)
3f81a9: 2B42 MOV *-SP[2], #0
3f81aa: 5206 CMPB AL, #0x6
3f81ab: 670F SB C$L8, HIS[/quote]

You question why, in the above sequence of instructions, AL is compared against the constant 6 without first loading AL from *-SP[2].  I can see why you suspect a bug in the compiler.  But there is not enough here to be sure.  Please send me the source to the function which produces this code, probably preprocessed like this.  Attach it to your next post by using the icon that looks like a paper clip.  I also need to know the exact version of the compiler (not CCS) you use, as well as the exact compiler options.

[quote user="Hubert Huang"]I know I should declare flag0 with volatile when it is global and used in interrupt.[/quote]

Any global which can be modified by an interrupt, or any thread of execution outside the main thread, must be declared volatile.  If, during the interrupt, the global is only read and never changes, then it does not need to be declared volatile.

[quote user="Hubert Huang"]I want to know why it does matter with "for(j = 0; j < 6; j++)".[/quote]

I can only answer in a general sense.  Volatile variables must be read and written exactly as the original source does.  The compiler is not allowed to optimize the code by arranging for the variable to live in a register for some range of instructions.  This limitation not only affects how the volatile variable is handled, but indirectly affects the instructions near those volatile variable accesses.

Thanks and regards,

-George


Viewing all articles
Browse latest Browse all 91752

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>