While writing a program for an MSP430G2432 in CCS Version: 5.3.0.00090 I get strange behaviour of the compiler: If I declare a local variable in one of the subroutines, sometimes the compiler totally ignores all lines that use this variable (even resulting in an "unused variable" warning during compilation)
When looking at the assembler, the compiler doesn't translate these lines (see example below)
When stepping with the debugger, it skips the "result=chargerLimit>0;" line and jumps to "chargerLimit=roomTempValue+chargerLimit>>6;" even tough chargerLimit is negative so 'result' should be 0.
If I try to display 'result' it says it doesn't exist... (unless I declare it o be volatile, but then it still does the 'if' statement wrong....)
I am running in Debug configuration, so the compiler is not doing any optimisation.
[Steps Needed to Recreate Problem:
the function below:
void tempAdjustChargerLimit(signed int roomTempValue)
{
char result=0;
relTemp = 3; // (:) getTemp()-eeprom[0]; // relative temperature: about 1.15 LSB/deg (combined effect of MCU sensor and D9 zener on PCB)
chargerLimit=((int)(64*CHARGELIMITGRAD)*relTemp);
relTemp = 3; // (:) getTemp()-eeprom[0]; // relative temperature: about 1.15 LSB/deg (combined effect of MCU sensor and D9 zener on PCB)
result=chargerLimit>0;
if (result)
chargerLimit=roomTempValue+chargerLimit>>6; // regular shift to divide back by 64 for positive number
else
chargerLimit=roomTempValue-(-chargerLimit)>>6; // r4everse sign if negative!
}
is compiled to:
516 {
tempAdjustChargerLimit:
ec3e: 4C0F MOV.W R12,R15
518 relTemp = 3; // (:) getTemp()-eeprom[0]; // relative temperature: about 1.15 LSB/deg (combined effect of MCU sensor and D9 zener on PCB)
ec40: 40B2 0003 0218 MOV.W #0x0003,&relTemp
519 chargerLimit=((int)(64*CHARGELIMITGRAD)*relTemp);
ec46: 421C 0218 MOV.W &relTemp,R12
ec4a: 403D FF77 MOV.W #0xff77,R13
ec4e: 12B0 EE0A CALL #__mpyi
ec52: 4C82 0216 MOV.W R12,&chargerLimit
520 relTemp = 3; // (:) getTemp()-eeprom[0]; // relative temperature: about 1.15 LSB/deg (combined effect of MCU sensor and D9 zener on PCB)
ec56: 40B2 0003 0218 MOV.W #0x0003,&relTemp
523 chargerLimit=roomTempValue+chargerLimit>>6; // regular shift to divide back by 64 for positive number
ec5c: 5F0C ADD.W R15,R12
ec5e: 12B0 EB84 CALL #I_ASR_6
ec62: 4C82 0216 MOV.W R12,&chargerLimit
526 }
ec66: 4130 RET