Dear All,

I define an array inside a function.
Unfortunately, all the elements of the array initialized by 0x30,
instead of the given values.
The array can placed in __code, but has the same behaviour.

Alex


SDCC : pic16/pic14 2.8.4 #5250 (Oct 12 2008) (UNIX)

The function:
//----------------------------------------------------
unsigned char conversion_by_table(unsigned char index)
{
  unsigned char conversion_table[4] ={'0x01','0x02','0x03','0x04'};
  return conversion_table[index & 0x03];
}
//----------------------------------------------------

The generated code:
;----------------------------------------------------
S_main__conversion_by_table     code
_conversion_by_table:
;       .line   42; main.c      unsigned char conversion_by_table(unsigned char 
index)
        MOVFF   FSR2L, POSTDEC1
        MOVFF   FSR1L, FSR2L
        MOVFF   r0x00, POSTDEC1
        MOVFF   r0x01, POSTDEC1
        MOVLW   0x02
        MOVFF   PLUSW2, r0x00
;       .line   44; main.c      unsigned char conversion_table[4]
={'0x01','0x02','0x03','0x04'};
        MOVLW   0x30
        BANKSEL _conversion_by_table_conversion_table_1_1
        MOVWF   _conversion_by_table_conversion_table_1_1, B
        MOVLW   0x30
        BANKSEL (_conversion_by_table_conversion_table_1_1 + 1)
        MOVWF   (_conversion_by_table_conversion_table_1_1 + 1), B
        MOVLW   0x30
        BANKSEL (_conversion_by_table_conversion_table_1_1 + 2)
        MOVWF   (_conversion_by_table_conversion_table_1_1 + 2), B
        MOVLW   0x30
        BANKSEL (_conversion_by_table_conversion_table_1_1 + 3)
        MOVWF   (_conversion_by_table_conversion_table_1_1 + 3), B
;       .line   45; main.c      return conversion_table[index & 0x03];
        MOVLW   0x03
        ANDWF   r0x00, F
        CLRF    r0x01
        MOVLW   LOW(_conversion_by_table_conversion_table_1_1)
        ADDWF   r0x00, F
        MOVLW   HIGH(_conversion_by_table_conversion_table_1_1)
        ADDWFC  r0x01, F
        MOVFF   r0x00, FSR0L
        MOVFF   r0x01, FSR0H
        MOVFF   INDF0, r0x00
        MOVF    r0x00, W
        MOVFF   PREINC1, r0x01
        MOVFF   PREINC1, r0x00
        MOVFF   PREINC1, FSR2L
        RETURN  
;----------------------------------------------------


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to