From: SourceForge.net <no...@so...> - 2003-08-14 15:45:57
|
Bugs item #788167, was opened at 2003-08-13 18:25 Message generated for change (Comment added) made by bernhardheld You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=788167&group_id=599 Category: msc51(8051) target >Group: non bugs >Status: Closed >Resolution: Rejected Priority: 5 Submitted By: Nobody/Anonymous (nobody) >Assigned to: Bernhard Held (bernhardheld) Summary: SDCC Compiler Bug... Initial Comment: ... or optimizer bug. My code void TransmitPacket() { unsigned char n; CE = 1; Delay100us(1); SpiReadWrite(shockbase[0x08]); SpiReadWrite(shockbase[0x09]); SpiReadWrite(shockbase[0x0A]); SpiReadWrite(shockbase[0x0B]); for(n=0;n<20;n++) { SpiReadWrite(n); } CE = 0; Delay100us(100); } Does not compile/optimize the FOR loop correct! However changing datatype for [n] to [char] will get the code to work. Both CHAR and UCHAR asmlisting for the loop is attached below. Compiler version [2.3.5] [Apr 21 2003] [MINGW32] //best regards //Jörgen Tapani //jo...@te... /////////////////////////////////////////////////// //with char n; ;pcu.c:95: for(n=0;n<20;n++) ; genAssign mov r2,#0x00 00101$: ; genCmpLt ; genCmp clr c mov a,r2 xrl a,#0x80 subb a,#0x94 ; genIfxJump ; Peephole 108 removed ljmp by inverse jump logic jnc 00104$ 00109$: ;pcu.c:97: SpiReadWrite(n); ; genCall mov dpl,r2 push ar2 lcall _SpiReadWrite pop ar2 ;pcu.c:95: for(n=0;n<20;n++) /////////////////////////////////////////////////// /////////////////////////////////////////////////// //with unsigned char n; ;pcu.c:95: for(n=0;n<20;n++) ; genAssign mov r2,#0x00 00101$: ; genCmpLt ; genCmp cjne r2,#0x14,00109$ 00109$: ; genIfxJump ; Peephole 108 removed ljmp by inverse jump logic jnc 00104$ 00110$: ;pcu.c:97: SpiReadWrite(n); ; genCall mov dpl,r2 push ar2 lcall _SpiReadWrite pop ar2 ;pcu.c:95: for(n=0;n<20;n++) /////////////////////////////////////////////////// ---------------------------------------------------------------------- >Comment By: Bernhard Held (bernhardheld) Date: 2003-08-14 14:08 Message: Logged In: YES user_id=203539 The first time I've seen this code, I also though it's buggy. But it's perfectly correct: cjne sets the carry flag if r2 < 0x14, which can be tested by jnc. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=788167&group_id=599 |