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

help!why not use Rx as loop counter?

I have a problem. I write a function in another c source file not main file, in this function nothing do, and I declare the function as extern. In main function I invoke it 200 times. However, the compiler does not use registerbank as counter. Why?

extern void func1(void);

void func2(void)
{
        unsigned char data i;
        for(i=200;i;i--);
}

main()
{
        unsigned char data i,j;
        for(i=200;i;i--)        // store i in 0x08
        {
                func1();
        }
        for(j=200;j;j--)        // store j in R6
        {
                func2();
        }
}
the assembly code:
C:0x0003    7508C8   MOV      0x08,#TMR2CN(0xC8)
    19:         {
    20:                 func1();
C:0x0006    120025   LCALL    func1(C:0025)
    21:         }
C:0x0009    D508FA   DJNZ     0x08,C:0006
    22:         for(j=200;j;j--)
C:0x000C    7EC8     MOV      R6,#TMR2CN(0xC8)
    23:         {
    24:                 func2();
C:0x000E    120020   LCALL    func2(C:0020)
    25:         }
C:0x0011    DEFB     DJNZ     R6,C:000E

Parents
  • Keil has somehow forgotten to specify if "data" binds to the left or to the right, but their own placement of the keyword does give an indication that it binds to the variable and not to the type, i.e. that it follows Andys example.

    Compare with * for pointesrs, i.e.

    unsigned char * i,j;
    


    may look like

    unsigned char* i;
    unsigned char* j;
    


    but is actually:

    unsigned char *i;
    unsigned char j;
    

Reply
  • Keil has somehow forgotten to specify if "data" binds to the left or to the right, but their own placement of the keyword does give an indication that it binds to the variable and not to the type, i.e. that it follows Andys example.

    Compare with * for pointesrs, i.e.

    unsigned char * i,j;
    


    may look like

    unsigned char* i;
    unsigned char* j;
    


    but is actually:

    unsigned char *i;
    unsigned char j;
    

Children
No data