??? 06/27/10 19:53 Read: times Msg Score: +3 +2 Informative +1 Good Answer/Helpful |
#176942 - Compare with zero is better Responding to: ???'s previous message |
It is normally better to write:
if (--multiplier == 0) { multiplier = 20; ... } Processor have dedicated hardware to compare with zero, since zero is a very special and and unique number. Processors doesn't have any hardware able to compare with 20, which means that it needs the constant 20 to perform the comparison. If you look at the instruction sets for processors (it doesn't really matter which processor you look at), you will notice that they have a special zero flag that gets set by a number of instructions if the result of the instruction is zero. If you compare with 20, then the processor will basically have to subtract 20 from your variable, to see if the result was zero. |
Topic | Author | Date |
Ideas for Multi-tap keyboard routine | 01/01/70 00:00 | |
just follow | 01/01/70 00:00 | |
Multi-tap is not too difficult | 01/01/70 00:00 | |
Two-step operation. Keyboard input + post-processing | 01/01/70 00:00 | |
State Machine! | 01/01/70 00:00 | |
Agree 100% | 01/01/70 00:00 | |
Time to code | 01/01/70 00:00 | |
Software Timers! | 01/01/70 00:00 | |
Practical Limits | 01/01/70 00:00 | |
Don't lock up in infinite loops everywhere | 01/01/70 00:00 | |
In the pseudo code... | 01/01/70 00:00 | |
State Machine | 01/01/70 00:00 | |
Divide by 5 | 01/01/70 00:00 | |
Timer resolution | 01/01/70 00:00 | |
State Machine | 01/01/70 00:00 | |
Looks not bad programming practice | 01/01/70 00:00 | |
Using Timer May Still be Possible | 01/01/70 00:00 | |
Done ! | 01/01/70 00:00 | |
Very Cool!!! | 01/01/70 00:00 | |
Compare with zero is better | 01/01/70 00:00 | |
Avoid ISR jitter using timer T1 | 01/01/70 00:00 | |
Code! | 01/01/70 00:00 | |
Thanks Munish...![]() | 01/01/70 00:00 |