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?
Steam-driven or not. The problem is that an instruction-counting loop written in C will always be at the mercy of whatever optimization the compiler may feel in a mood to supply. Per, I diverted from "just delays" to the fact than ever so many get lost in "optimizing the compiler". Looking at the OPs issue, 1) he don't care about precision 2) he want the compiler to "do the optimal" and (s)he has now wasted days on something that does not matter. The issue is that if it is not super critical, WHO THE #&!! CARES how optimal the compiler generated code is. This is, by no means, not the first post we have seen "why does the compiler not generate code as efficient as i (believe) I can do in assembler. Since the 1 and 2 clockers appeared (1995?) I have, without ever running the optimizer beyond level 2, had only ONE case where I had to do assembler for a function.
Erik
PS "without ever running the optimizer" I do not believe in releasing code that is not debuggable. I have had an experience where someone needed help "my code fails, but runs when I debug (no optimize)" he was developing with more memory than the production model (a valid case if you produce millions of units, his market was about 100) BTW, the problem WAS a timing loop.