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?
Actually, in the usual figurative meaning of that phrase, it is.
That is very disturbing.
Your side lost it decades ago, but every new generation of programmers refuses to admit it.
That is even more disturbing.
Eric,
I'd still suggest you consider writing your delay in assembler. Any seasoned low level programmer knows when the use of a software delay is sensible and would code it accordingly, so any statement by a person on whether it is right or wrong of it is just showing their ignorance.
Even if a zealous bigot responder here has a way of causing the compiler to use the DJNZ, it's really not sensible to rely on it. Any number of things could cause the compiler to change it's mind so your code could simply break at a future point in time. Write it in assembler, and you know it is safe from these compiler decisions.