From: Michael S. <msc...@ba...> - 2000-09-01 11:37:02
|
I had just traped into the following problem with the peephole 132 i have a source that looks like that switch( a ) case a1: do something break; switch( b ) case b1: do something break; case B2: do something break; case b3: do something break; break; // no default ! case a2: do something break; case a3: do something break; case a4: do something break; now my problem was that case b1: was never executed but should be. it took my hours of hacking, debugging and hacking ... until i looked into the lst file .. 0750 90s00r00 2198 mov dptr,#_HostCmd 0753 E0 2199 movx a,@dptr 0754 FA 2200 mov r2,a 0755 8A*00 2201 mov _HostCommand_tmp_uchar_1_1,r2 0757 2202 C$wsi_128kflash.c$712$2$2 ==. 2203 ; wsi_128kflash.c 712 0757 C2 95 2204 clr _P1_5 0759 2205 C$wsi_128kflash.c$713$2$2 ==. 2206 ; wsi_128kflash.c 713 0759 D2 95 2207 setb _P1_5 075B 2208 C$wsi_128kflash.c$714$2$2 ==. 2209 ; wsi_128kflash.c 714 075B BA 41 03 2210 cjne r2,#0x41,00417$ 075E 02s09rCC 2211 ljmp 00210$ 0761 2212 00417$: 0761 BA 42 02 2213 cjne r2,#0x42,00418$ 2214 ; Peephole 132 changed ljmp to sjmp 0764 80 81 2215 sjmp 00179$ 0766 2216 00418$: 0766 BA 43 03 2217 cjne r2,#0x43,00419$ 0769 02s08r45 2218 ljmp 00183$ some lines later ... 07DE 2276 00438$: 07DE BA 57 03 2277 cjne r2,#0x57,00439$ 07E1 02s09rCC 2278 ljmp 00210$ 07E4 2279 00439$: 07E4 02s09rCF 2280 ljmp 00222$ 07E7 2281 C$wsi_128kflash.c$724$3$17 ==. 2282 ; wsi_128kflash.c 724 07E7 2283 00179$: 07E7 C2 95 2284 clr _P1_5 07E9 2285 C$wsi_128kflash.c$725$3$17 ==. 2286 ; wsi_128kflash.c 725 now line 2215 is the above case b1 and the lst file looks like the cases are re-ordered. the first thing i noticed was that for this case a peephole has changed ljmp to sjmp my first idea was that this could be the reason and the instruction is wrong. so i modified my sources a bit switch( a ) case a1: do something break; switch( b ) --> default : waste time; break; // no need for that case b1: do something break; case B2: do something break; case b3: do something break; break; // no default ! case a2: do something break; notice that default case before the not executed case. with this extra, not needed, code my sources works as expected the case is executed. I quick view into the lst file shows that the sjmp is now a ljmp. so could it be that 0764 80 81 2215 sjmp 00179$ 07E7 2283 00179$: is wrong ? 0x7E7-0x764 - 2byte code = 0x81 but doesn't 0x81 mean a jump backwards to 0x6E3 or so ? this would explain something ? i am not shure but i thought that it is only possible to do a short jump -128 .. +127 and 0x81 is negative .... Ah, one last thing to mention. The sdcc-built is the same as the one i have sent to the OKR. i made it from the cvs sources august 28. But earlier versions also showed that. Dipl.-Ing. (FH) Michael Schmitt Baumer Ident GmbH Entwicklung / Development Department Hertzstr. 10 D-69469 Weinheim Deutschland / Germany Tel. +49 (0) 6201 9957 - 30 Fax. +49 (0) 6201 9957 - 99 E-Mail : msc...@ba... Web: http://www.baumerident.com |