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

Useless Moves

Is there a way to change the DEFINE statement to get rid of the two useless mov(s)?

C51 COMPILER V6.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\MAIN.OBJ
COMPILER INVOKED BY: C:\PROGRAM FILES\KEIL\C51\BIN\C51.EXE .\MAIN.C OPTIMIZE(7,SPEED) NOINTPROMOTE MODDP2 DEBUG OBJECTEX
                    -TEND CODE SYMBOLS NOCOND

stmt level    source

   1          typedef unsigned char BYTE;
   2          typedef unsigned int  WORD;
   3          
   4          typedef pdata struct 
   5          {
   6            BYTE PC0           :1;
   7            BYTE PC1           :1;
   8            BYTE nFifoPend     :1; //PC2
   9            BYTE PC3           :1;
  10            BYTE FpgaReset     :1; //PC4
  11            BYTE PC5           :1;
  12            BYTE PC6           :1;
  13            BYTE PC7           :1; 
  14          } CType;
  15          
  16          extern volatile BYTE pdata xOUTC;
  17          
  18          #define IoPins_FpgaReset ( ((CType pdata*)(&xOUTC))->FpgaReset )
  19          
  20          void main(void)
  21          {
  22   1        IoPins_FpgaReset = 1;
  23   1      }
  24          
  25          


             ; FUNCTION main (BEGIN)
                                           ; SOURCE LINE # 20
                                           ; SOURCE LINE # 21
                                           ; SOURCE LINE # 22
0000 7A00        E     MOV     R2,#HIGH xOUTC
0002 7900        E     MOV     R1,#LOW xOUTC
0004 7800        E     MOV     R0,#LOW xOUTC
0006 E2                MOVX    A,@R0
0007 4410              ORL     A,#010H
0009 F2                MOVX    @R0,A
                                           ; SOURCE LINE # 23
000A 22                RET     
             ; FUNCTION main (END)

Parents
  • There are several problems in the program that you have that cause the superfluous moves. They are:

    1. The pdata in the typedef does nothing so it should be removed.

    2. The volatile on the "extern BYTE pdata xOUTC" is not necessary and it is what causes the goofy access to get the address of xOUTC.

    3. The volatile chould be placed on the pointer derefencing (in the #define).


    The following minor modificationto your program generates the desired results:

    typedef unsigned char BYTE;
    typedef unsigned int  WORD;
    
    //typedef pdata struct 
    typedef struct 
    {
      BYTE PC0           :1;
      BYTE PC1           :1;
      BYTE nFifoPend     :1; //PC2
      BYTE PC3           :1;
      BYTE FpgaReset     :1; //PC4
      BYTE PC5           :1;
      BYTE PC6           :1;
      BYTE PC7           :1; 
    } CType;
    
    extern BYTE pdata xOUTC;
    
    #define IoPins_FpgaReset ( ((CType volatile pdata *) &xOUTC)->FpgaReset )
    
    void main(void)
    {
      IoPins_FpgaReset = 1;
    }

    The code generated is as follows:

    0000 7800        E     MOV     R0,#LOW xOUTC
    0002 E2                MOVX    A,@R0
    0003 4410              ORL     A,#010H
    0005 F2                MOVX    @R0,A
                                               ; SOURCE LINE # 24
    0006 22                RET     
                 ; FUNCTION main (END)
    

    Jon

Reply
  • There are several problems in the program that you have that cause the superfluous moves. They are:

    1. The pdata in the typedef does nothing so it should be removed.

    2. The volatile on the "extern BYTE pdata xOUTC" is not necessary and it is what causes the goofy access to get the address of xOUTC.

    3. The volatile chould be placed on the pointer derefencing (in the #define).


    The following minor modificationto your program generates the desired results:

    typedef unsigned char BYTE;
    typedef unsigned int  WORD;
    
    //typedef pdata struct 
    typedef struct 
    {
      BYTE PC0           :1;
      BYTE PC1           :1;
      BYTE nFifoPend     :1; //PC2
      BYTE PC3           :1;
      BYTE FpgaReset     :1; //PC4
      BYTE PC5           :1;
      BYTE PC6           :1;
      BYTE PC7           :1; 
    } CType;
    
    extern BYTE pdata xOUTC;
    
    #define IoPins_FpgaReset ( ((CType volatile pdata *) &xOUTC)->FpgaReset )
    
    void main(void)
    {
      IoPins_FpgaReset = 1;
    }

    The code generated is as follows:

    0000 7800        E     MOV     R0,#LOW xOUTC
    0002 E2                MOVX    A,@R0
    0003 4410              ORL     A,#010H
    0005 F2                MOVX    @R0,A
                                               ; SOURCE LINE # 24
    0006 22                RET     
                 ; FUNCTION main (END)
    

    Jon

Children