Why does the naive delay in chapter 9 require a NOP, but the timer-based delay does not? #507
Unanswered
JackNWhite
asked this question in
Q&A
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). |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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.
All reactions