| ??? 01/22/03 13:33 Read: times |
#36943 - RE: volatile keyword |
void foo(void){
volatile int i;
ACC = i;
}"Does this force the compiler to bypass optimization and generates code to read i into the ACCUMLATOR?"
You have asked two questions there! As Menno said, the answers to your questions are "yes" and "no" respectively: Yes - the volatile keyword does force the compiler to bypass optimization for that variable; No - the volatile keyword does not force the compiler to generate code to read i into the ACCUMLATOR. Note that the 8051 is an 8-bit processor, so the Accumulator has only 8 bits; an int is likely to have 16 bits (check your compiler Manual) - so this code may well not be doing quite what you wanted... You should also note that there is no guarantee that the compiler will not use the Accumulator (or any other Register) for its own purposes - so there is no guarantee that the Accumulator will still contain the value you loaded by the time your code reaches the next 'C' statement! This is particularly so if you're using 16-bit (or larger) values on an 8-bit processor - since the processor will very likely have to use the Accumulator for the intermediate operations! |
| Topic | Author | Date |
| volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
| RE: volatile keyword | 01/01/70 00:00 | |
volatile keyword and not-so-optimizer | 01/01/70 00:00 |



