What exactly we want to achieve in delay function? #361
-
Hi, I am going through this discovery book and I have successfully completed it till chapter 8 Leds Again. Now in chapter 9 Clock and timers i was going through these for loop delays using function delay but I am not getting what actually we want to achieve and what this loop is doing in function delay. Can someone please help me with this? I know we are not using delay as we were using it in the previous chapter we have to work with it differently. Okay so I know why we are using nop here I just want to understand the working of constant k & for loop |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @NitinSaxenait, sections 9 is about shedding some light on the internals of a delay function to give you an impression how it could be implemented. It sketches two common approaches:
Without any special measures, the compiler will optimize away an empty loop. But it offers a "blessed no operation" which won't: The function The constant |
Beta Was this translation helpful? Give feedback.
Hello @NitinSaxenait, sections 9 is about shedding some light on the internals of a delay function to give you an impression how it could be implemented. It sketches two common approaches:
Without any special measures, the compiler will optimize away an empty loop. But it offers a "blessed no operation" which won't: The function
aux9::nop
resolves to the compiler intrinsic__nop
which serves exactly this purpose.The constant
K
is the number of loop iterations you have to perform for a millisecond. SoK * ms
is the nu…