Forum Discussion
Altera_Forum
Honored Contributor
12 years agoThe debugger reporting a variable as 'optimised out' just means that that the variable is never assigned to a physical memory location, so it could still exist but always be assigned to a register.
The compiler is allowed to remove any calculations where the resultant value isn't used - in this case that collapses back to your entire delay loops being removed. You could just try declaring the variables as 'volatile int delay1;' that might be enough to stop the loops being (validly) optimised away. Or add something to the inner loop that the compiler cannot remove. eg: define a program scope 'volatile int temp;' and write something to it. or: an asm statement that generates no object code: asm volatile ("\n");