Dark.Rider 0 Posted June 22, 2005 Report Share Posted June 22, 2005 Hello! Here is my problem, probably a bug: Bug description: a comparison between two signed chars seems not to work correclty Steps to reproduce: here my code sniplet: signed char DefaultAction(signed char cIst, signed char cSoll) { signed char cAccel; if(cIst == cSoll) return(0); cAccel=1; if(opposite(cIst,cSoll)) cAccel=4; if(cSoll==0) cAccel=2; //HERE IS THE PROBLEM if(cIst>cSoll) cAccel=-cAccel; //Example: cIst=-90 cSoll=0 and the statement gets TRUE //(cAccel old value=2 new value=-2) 100% tested with the debugger //Assembler code for this statement //006E 0832 MOVF DefaultAct_00005_arg_cIst, W //006F 1003 BCF STATUS,C //0070 1BB2 BTFSC DefaultAct_00005_arg_cIst,7 //0071 0233 SUBWF DefaultAct_00005_arg_cSoll, W //0072 1FB3 BTFSS DefaultAct_00005_arg_cSoll,7 //0073 0233 SUBWF DefaultAct_00005_arg_cSoll, W //0074 1803 BTFSC STATUS,C //0075 2879 GOTO label268436421 //0076 0934 COMF DefaultAct_00005_1_cAccel, W //0077 00B4 MOVWF DefaultAct_00005_1_cAccel //0078 0AB4 INCF DefaultAct_00005_1_cAccel, F //0079 label268436421 if(bSpinTurn) cAccel+=cAccel; return(cAccel); } Expected behaviour: It should do the opposithe thing Is the problem 100% reproduceable: It happens EVERY time at this statement IDE version: SourceBoost IDE version 6.01 Compiler: BoostC Target device: PIC16F873 OS: Win2k Comments: Please help! I would like to change from cc5x because of limitations and price. But the compiler should work correctly Quote Link to post Share on other sites
Pavel 0 Posted June 23, 2005 Report Share Posted June 23, 2005 What is 'opposite'? Regards, Pavel Quote Link to post Share on other sites
Dark.Rider 0 Posted June 23, 2005 Author Report Share Posted June 23, 2005 (edited) Hello! What is 'opposite'? <{POST_SNAPBACK}> signed char opposite(signed char a, signed char B ) { if((a^ B ) <0 && a && B ) return TRUE; return FALSE; } I commented it out, no change. I just tested a simple program: #include <system.h> signed char a,b,c; main() { a=-90; b=0; c=0; if( a>b ) c=1; for(;; } c becomes '1'!!! The comparison seems be done unsigned. Here the casm: main() { a=-90; 0003 30A6 MOVLW 0xA6 0004 1283 BCF STATUS, RP0 0005 1303 BCF STATUS, RP1 0006 00A0 MOVWF gbl_a b=0; 0007 01A1 CLRF gbl_b c=0; 0008 01A2 CLRF gbl_c if(a> c=1; 0009 0820 MOVF gbl_a, W 000A 1003 BCF STATUS,C 000B 1BA0 BTFSC gbl_a,7 000C 0221 SUBWF gbl_b, W 000D 1FA1 BTFSS gbl_b,7 000E 0221 SUBWF gbl_b, W 000F 1803 BTFSC STATUS,C 0010 2813 GOTO label268436063 0011 3001 MOVLW 0x01 0012 00A2 MOVWF gbl_c 0013 label268436063 for(;; 0013 2813 GOTO label268436063 } regards Thomas Kusch Edited June 23, 2005 by Dark.Rider Quote Link to post Share on other sites
Pavel 0 Posted June 23, 2005 Report Share Posted June 23, 2005 Yes this looks like a bug Will work on it today. A compiler fix will be released as soon as this one gets fixed. Thanks for reporting. Regards, Pavel Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.