Why does the naive delay in chapter 9 require a NOP, but the timer-based delay does not? #507
Replies: 1 comment
-
Typical release builds will turn on compiler optimizations which perform a semantically equivalent transformation of your input program. As the You have to take special measures to protect such an instructrion from being optimized away. When checking whether the timer has been elapsed, the magic is already built it. This bit is declared to be externally modified so that the compiler does not assume the value it reads for the first time will be there forever (as its code does not manipulate it). |
Beta Was this translation helpful? Give feedback.
-
If you remember, the original delay function is:
And the final function is:
I have checked the debug and release builds for both, and the former, as you find in the book, works only under debug conditions, while the latter works under both debug and release conditions. I don't see why the compiler would make the distinction.
Beta Was this translation helpful? Give feedback.
All reactions