Hello experts,
as an example I have a C-program.
int8_t var_8;
int16_t var_16;
int32_t var_32;
int64_t var_64;
float32_t var_f32;
float64_t var_f64;
#pragma INTERRUPT(Interrupt_Routine)
void Interrupt_Routine(void)
{
//Variables var_... are modified here
//var_ = var_8, var_16, ....
...
}
main(void)
{
//Variables var_... are used here but not modified
//Use in such commands as
// ... = var_... + ...;
// if(var_... >= 0)
...
}
The C compiler translates the C syntaxes into assembler instructions.
As long as var_... stands as a whole in an assembler instruction, the validity of the variable value is guaranteed, because the assembler instruction with 1 CYC cannot be interrupted by interrupt. The assembler instruction is atomic.
My question:
Is the use of the variable var_... in main() always safe? Or can it happen this way that the compiler does not treat a variable as whole.
For example:
C-syntax: tmp1_64 = var_64 + 10LL;
Compiler translates the C-syntax to:
Assembler_Instruction_1: (tmp1_64)_32_bit_Lowpart = (var_64)_32_bit_Lowpart + 10L;
Assembler_Instruction_2: (tmp1_64)_32_bit_Highpart = (var_64)_32_bit_Highpart + Carry_Flag;
Between Assembler_Instruction_1 and Assembler_Instruction_2 an interrupt can come and we then have to deal with an invalid value of var_64.
The example can also be used for other variables like var_32, var_16, var_f64, ... as well as extend for other C syntaxes.
Thanks in advance - Bui



