Skip to main content
Visitor II
July 31, 2007
Question

Compiler problem again?

  • July 31, 2007
  • 2 replies
  • 745 views
Posted on July 31, 2007 at 10:32

Compiler problem again?

    This topic has been closed for replies.

    2 replies

    lseletronAuthor
    Visitor II
    July 30, 2007
    Posted on July 30, 2007 at 04:38

    Hi,

    I followed Luca's recommendation and installed the latest Cosmic compiler. Now the .ls file says at the beginning:

    1 ; C Compiler for ST7 (COSMIC Software)

    2 ; Generator V4.5.5 - 12 Jan 2006

    3 ; Optimizer V4.4.2 - 11 Jan 2006

    But I still have problems with my program. In the following code

    line 1:unsigned char l_ShortAddress;

    line ;

    line 3:if(((g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110)>>1)==g_MyDaliSettings.m_ShortAddress)

    line 4:{

    line 5:retval=DALI_NORMAL_COMMAND_FOR_ME;

    line 6:}

    line 5 will not be executed as it should. I fix the problem by uncommenting line 2, which is weird as line 2 does nothing useful.

    Here is the translation for both cases (line 2 commented and not commented):

    // Commented, not working properly:

    2788 switch .text

    2790 xref _IsDaliPacketForMe$L

    2791 0cf5 _IsDaliPacketForMe:

    2792 ; 1294 unsigned char retval=DALI_COMMAND_NOT_FOR_ME;

    2793 0cf5 a601 ld a,#1

    2794 0cf7 c7ffff ld _IsDaliPacketForMe$L-1,a

    2795 ; 1296 if (0==GetBit(g_DaliPacket[DALI_ADDRESS_BYTE],B_7))

    2796 0cfa c6003f ld a,_g_DaliPacket

    2797 0cfd 2b17 jrmi L306

    2798 ; 1301 if(((g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110)>>1)==g_MyDaliSettings.m_ShortAddress)

    2799 0cff 5f clr x

    2800 0d00 90ce0028 ld y,_g_MyDaliSettings+4

    2801 0d04 3f00 clr c_y

    2802 0d06 b300 cp x,c_y

    2803 0d08 2703cc0da6 jrne L706

    2804 0d0d 90bf01 ld c_y+1,y

    2805 0d10 b101 cp a,c_y+1

    2806 0d12 26f6 jrne L706

    2807 ; 1303 retval=DALI_NORMAL_COMMAND_FOR_ME;

    // Not commented working OK

    2788 switch .text

    2790 xref _IsDaliPacketForMe$L

    2791 0cf5 _IsDaliPacketForMe:

    2792 ; 1294 unsigned char retval=DALI_COMMAND_NOT_FOR_ME;

    2793 0cf5 a601 ld a,#1

    2794 0cf7 c7ffff ld _IsDaliPacketForMe$L-1,a

    2795 ; 1296 if (0==GetBit(g_DaliPacket[DALI_ADDRESS_BYTE],B_7))

    2796 0cfa c6003f ld a,_g_DaliPacket

    2797 0cfd 2b1b jrmi L306

    2798 ; 1300 l_ShortAddress=g_MyDaliSettings.m_ShortAddress;

    2799 0cff c60028 ld a,_g_MyDaliSettings+4

    2800 0d02 c7fffe ld _IsDaliPacketForMe$L-2,a

    2801 ; 1301 if(((g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110)>>1)==g_MyDaliSettings.m_ShortAddress)

    2802 0d05 5f clr x

    2803 0d06 9097 ld y,a

    2804 0d08 3f00 clr c_y

    2805 0d0a b300 cp x,c_y

    2806 0d0c 2703cc0daa jrne L706

    2807 0d11 90bf01 ld c_y+1,y

    2808 0d14 b101 cp a,c_y+1

    2809 0d16 26f6 jrne L706

    2810 ; 1303 retval=DALI_NORMAL_COMMAND_FOR_ME;

    Why does this happen?

    I am doing something wrong?

    Thanks

    Visitor II
    July 31, 2007
    Posted on July 31, 2007 at 10:32

    Hi,

    There is an optimizer problem here. You should try a more efficient syntax by casting the result of the shift back to (unsigned char), as the C standard rules are considering the result of any operator as at least an int. Forcing the shift result to a char will allow a direct char compare and the optimizer will not fail with the widening:

    if((unsigned char)((g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110)>>1)==g_MyDaliSettings.m_ShortAddress)

    And the resulting code will be more efficient.