AnsweredAssumed Answered

Code is getting optimized, 

Question asked by Pratik Patil on Mar 22, 2017
Latest reply on Mar 23, 2017 by Radek Sestak

Hi,

 

My code is getting optimized, optimization is of value of global variable.

Example given below:

 

uint8 a = 0;  // Global variable

Function()

{

   a = 5;

   Modify(a);

}

 

modify(uint8 var)

{

   switch(var)

   {

      case 1:

 

      case 5: do

 

      default:

   }

}

 

We are passing global variable a, while passing value is 5.

But when it enters into called function modify then its value changes and automatically.

 

Adding a NOP instruction after variable function call resolves this issue, written below:

 

Function()

{

   a = 5;

   Modify(a);

   NOP

}

 

Optimization level is 2 and for space.

 

Can one explain how adding NOP changes the situation and why passed value changes?

Outcomes