From: SourceForge.net <no...@so...> - 2011-08-09 22:20:44
|
Bugs item #3389244, was opened at 2011-08-09 22:57 Message generated for change (Comment added) made by galzsolt You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3389244&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: pic14 target Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Gál Zsolt (galzsolt) Assigned to: Nobody/Anonymous (nobody) Summary: [PIC14] logical problem - if then - vs - if then else Initial Comment: SDCC : pic16/pic14 3.0.4 #6726 (Aug 9 2011) (Linux) There is problem in logical function where i use bit variables . Here is the two tipical syntax, first whithout else: if ( condition ) { expr_set1; } And with else: if ( condition ) { expr_set1; } else { expr_set2; } If I use "if" with "else" the compiled code is correct. If I don't use "else" the compiled code doesn't follow the original logic. I attached an example which will show clearly the differece. I wanted to make logical OR function but this compiled code doesen't follow it: .line 39; "logical_test.c" if( B0 && B2 ) BTFSS _b,0 GOTO _00118_DS_ BTFSS _b,2 .line 41; "logical_test.c" if( !B1 || !B3 ) B4 = 1; GOTO _00118_DS_ BTFSC _b,1 BTFSS _b,3 BSF _b,4 _00118_DS_ And the well working result with "else": .line 31; "logical_test.c" if( B0 && B2 ) BTFSS _b,0 GOTO _00109_DS_ BTFSS _b,2 GOTO _00109_DS_ BTFSS _b,1 GOTO _00105_DS_ BTFSC _b,3 GOTO _00110_DS_ _00105_DS_ BANKSEL _b BSF _b,4 GOTO _00110_DS_ _00109_DS_ .line 35; "logical_test.c" else B4 = 0; BANKSEL _b BCF _b,4 _00110_DS_ .line 38; "logical_test.c" B4 = 0; BANKSEL _b BCF _b,4 ---------------------------------------------------------------------- >Comment By: Gál Zsolt (galzsolt) Date: 2011-08-10 00:20 Message: Sorry for confusion. I wasn't enough attentive and I complained about a well working code. So here is the problematic code: .line 23; "logical_test.c" b.common_byte = 0x0B; MOVLW 0x0b BANKSEL _b MOVWF (_b + 0) .line 25; "logical_test.c" b.B4 = 0; BCF _b,4 .line 26; "logical_test.c" if( b.B0 && b.B1 ) BTFSS _b,0 GOTO _00001_DS_ BTFSS _b,1 .line 28; "logical_test.c" if( !b.B2 || !b.B3 ) c.B0 = 1; GOTO _00001_DS_ BTFSC _b,2 BTFSC _b,3 GOTO _00001_DS_ BANKSEL _c BSF _c,0 _00001_DS_ RETURN And I attached the source of it. I tested it by GPsim whith the following inputs in "b": 0x03 -> result: c = 0 ( it should be 1 ) 0x07 -> result: c = 1 0x0B -> result: c = 0 ( it should be 1 ) 0x0F -> result: c = 1 ( it should be 0 ) If I uncomment the "else NOP" line I get the correct result for these inputs. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=3389244&group_id=599 |