This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to get C51 to generate a DJNZ loop?

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?

Parents
  • At the rist of bragging, if you want specific assembler instruction sequences, use assembler.

    The job of the C51 is to create correct code, the job is not to create specific assembler code sequences you might want to have.

Reply
  • At the rist of bragging, if you want specific assembler instruction sequences, use assembler.

    The job of the C51 is to create correct code, the job is not to create specific assembler code sequences you might want to have.

Children