We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want a fast and simple delay routine:
#pragma OT(8,SPEED) // Switch to speed optimization for this routine void my_delay(BYTE count) { register BYTE i; for (i=count; i; i--); }
Is the best so far and becomes:
B02:0xB1F1 EF MOV A,R7 B02:0xB1F2 6003 JZ B02:B1F7 B02:0xB1F4 1F DEC R7 B02:0xB1F5 80FA SJMP I2C_delay(B02:B1F1) B02:0xB1F7 22 RET
but I was hoping there was a way to get C51 to do just a DJNZ instead of 4 instructions for each loop.
Is there a magic coding style or optimization level that will generate the DJNZ?
So you want the fastest 1ms delay the world has ever seen? :)
One thing to think about, is that you should always try to use pre-increment/pre-decremented whenever possible.
With post-increment, you are telling the compiler to keep a copy of the variable _before_ the increment, because you plan to use the old value after you have incremented.
It's so surprising to see someone write that! When I first moved from exclusive assembly to C, that was one of the first discoveries I made and have followed that same rule since.
For some reason the post increment is far more common. It looks like the language name C++ has had at least a partial influence there.
But mention it to many people and it's generally dismissed. We even had one of the posters of this forum do a code review for us a few years ago and he actually insisted that the post increment was not just favourable, but actually better. He was not open to persuasion either. Go figure!