Hi,
I'm having trouble with mspgcc version 3.2.3 accessing a variable
that's been declared as volatile twice, when my code refers to it
only once. This is a problem because that variable happens to be
I2CIV, the value of which changes upon access.
I've attempted to create the smallest piece of code that still
generates this fault (or, at least, what I regard to be a fault).
*** begin code ***
volatile int test;
int main( void )
{
int i;
switch( test )
{
case 0: i = 1; break;
case 1: i = 2; break;
case 2: i = 3; break;
case 3: i = 4; break;
case 4: i = 5; break;
case 5: i = 6; break;
case 6: i = 7; break;
case 7: i = 8; break;
}
}
*** end code ***
Then, the first few lines of the disassembly of the main function are:
0000fc40 <main>:
fc40: 31 40 7e 02 mov #638, r1 ;#0x027e
fc44: 04 41 mov r1, r4 ;
fc46: b2 92 00 02 cmp #8, &0x0200 ;r2 As==11
fc4a: 2a 2c jc $+86 ;abs 0xfca0
fc4c: 1f 42 00 02 mov &0x0200,r15 ;0x0200
fc50: 0f 5f rla r15 ;
fc52: 3f 50 5a fc add #-934, r15 ;#0xfc5a
fc56: 2f 4f mov @r15, r15 ;
fc58: 00 4f br r15 ;
Note that the code is accessing the switch variable twice, in the cmp
instruction at 0xfc46 and in the mov instruction at 0xfc4c.
This is fairly problematic, since when I switch on the value of I2CIV
in my I2C interrupt function I miss a large number of interrupts!
Is this a known problem? Is there a fix in a later version of gcc?
Cheers,
Rob