2007-07-26 01:31 PM
2007-07-25 04:34 PM
Hi,
I have the following code: line 1: unsigned char IsDaliPacketForMe(void) line 2: { line 3: unsigned char retval=1; line 4: unsigned char l_Tmp; line 5: l_Tmp=g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110; line 6: //l_Tmp=l_Tmp>>1; line 7: if((l_Tmp>>1)==g_MyDaliSettings.m_ShortAddress) line 8: { line 9: retval=2; line 10: } line 11: return retval; line 12: } The problem is that when the emulator runs with the Debug version, the condition in line 7 is true and the function returns 2. When the emulator runs the Release version (default optimization) the said condition is false and the function returns 1. The problem is fixed by having the right shift operation not in line 7, but in line 6: line 6: l_Tmp=l_Tmp>>1; line 7: if((l_Tmp)==g_MyDaliSettings.m_ShortAddress) Why does this happen? Is it me doing something wrong or is the compiler translating the code wrongly? From the assembly code (I pasted the code for both working and not working cases) it seems that in the case when the right shift is done in line 7, the SLR operation is missing: // THIS CODE WORKS ; 1294 unsigned char IsDaliPacketForMe(void) ; 1295 { switch .text xref _IsDaliPacketForMe$L _IsDaliPacketForMe: ; 1296 unsigned char retval=DALI_COMMAND_NOT_FOR_ME; ld a,#1 ld _IsDaliPacketForMe$L-2,a ; 1301 l_Tmp=g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110; ld a,_g_DaliPacket and a,#254 ; 1302 l_Tmp=l_Tmp>>1; srl a ; 1303 if((l_Tmp)==g_MyDaliSettings.m_ShortAddress) cp a,_g_MyDaliSettings+4 jrne L106 ; 1305 retval=DALI_NORMAL_COMMAND_FOR_ME; ld a,#2 ld _IsDaliPacketForMe$L-2,a L106: ; 1349 return retval; ld a,_IsDaliPacketForMe$L-2 ret // THIS CODE DOES NOT WORK PROPERLY ; 1294 unsigned char IsDaliPacketForMe(void) ; 1295 { switch .text xref _IsDaliPacketForMe$L _IsDaliPacketForMe: ; 1296 unsigned char retval=DALI_COMMAND_NOT_FOR_ME; ld a,#1 ld _IsDaliPacketForMe$L-2,a ; 1301 l_Tmp=g_DaliPacket[DALI_ADDRESS_BYTE]&0b011111110; ld a,_g_DaliPacket and a,#254 ld _IsDaliPacketForMe$L-1,a ; 1303 if((l_Tmp>>1)==g_MyDaliSettings.m_ShortAddress) clr x ld y,_g_MyDaliSettings+4 clr c_y cp x,c_y jrne L106 ld c_y+1,y cp a,c_y+1 jrne L106 ; 1305 retval=DALI_NORMAL_COMMAND_FOR_ME; ld a,#2 ld _IsDaliPacketForMe$L-2,a L106: ; 1349 return retval; ld a,_IsDaliPacketForMe$L-2 ret2007-07-25 10:29 PM
2007-07-26 01:31 PM
Hi,
during installation it said the version was 4.5.5 the shortcut on my desktop says it is version 4.5.5 when I run the compiler, its splash screen says 4.4.15 and when I click Help/About it says 4.4.15 So I dont know which version it really is, but is the latest free version from the Cosmic web site Thank you