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

array initialization efficiency

Hi,

I'm trying to cram my software into 8k and noticed the following regarding array initialization. Regardless of the size of the array, a call to a library function COPY is made. In the attached listing file, you can see that the COPY uses 19 bytes of code spac, while the same initialization could be done is 9 bytes of code. I'm typically using small arrays to update device parameters in i2c messages, the i2c code accepts a pointer to a buffer and buffer size of the data to transmit.

C51 COMPILER V7.20   MAIN                                                                  11/25/2004 10:54:54 PAGE 1


C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND CODE

line level    source

   1
   2
   3          void main ( void )
   4          {
   5   1              unsigned char temp[3] = {0xDE, 0xAD, 0xFF};
   6   1
   7   1              temp[0] = 0xC0;
   8   1              temp[1] = 0xFF;
   9   1              temp[2] = 0xEE;
  10   1
  11   1      }
C51 COMPILER V7.20   MAIN                                                                  11/25/2004 10:54:54 PAGE 2

ASSEMBLY LISTING OF GENERATED OBJECT CODE


             ; FUNCTION main (BEGIN)
                                           ; SOURCE LINE # 3
                                           ; SOURCE LINE # 4
                                           ; SOURCE LINE # 5
0000 7800        R     MOV     R0,#LOW temp
0002 7C00        R     MOV     R4,#HIGH temp
0004 7D00              MOV     R5,#00H
0006 7BFF              MOV     R3,#0FFH
0008 7A00        R     MOV     R2,#HIGH _?ix1000
000A 7900        R     MOV     R1,#LOW _?ix1000
000C 7E00              MOV     R6,#00H
000E 7F03              MOV     R7,#03H
0010 120000      E     LCALL   ?C?COPY
                                           ; SOURCE LINE # 7
0013 7500C0      R     MOV     temp,#0C0H
                                           ; SOURCE LINE # 8
0016 7500FF      R     MOV     temp+01H,#0FFH
                                           ; SOURCE LINE # 9
0019 7500EE      R     MOV     temp+02H,#0EEH
                                           ; SOURCE LINE # 11
001C 22                RET
             ; FUNCTION main (END)



MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     29    ----
   CONSTANT SIZE    =      3    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

Any thoughts on why the compiler always uses COPY instead of using it for arrays that have a size of greater then 5.

Thanks,
Frodak

0