|
|
View previous topic :: View next topic |
Author |
Message |
object01
Joined: 13 May 2004 Posts: 90 Location: Nashville, TN
|
Function won't return anything other than 0. |
Posted: Fri Jun 04, 2004 9:53 am |
|
|
I've been wrestling with what seems like a compiler bug. I'm hoping somebody can point out something I've missed.
The following code fragment from my program generates the listing that follows. There are two things I don't understand: first, the instruction at 0xA3A, GOTO 23B, actually goes to 0xA3B. Second, the only return statement in any of this is the RETLW 00, which according to the PIC16F88 data sheet will return 0. Sure enough, the function this code fragment comes from never returns anything but 0.
Notice the two commented return statements. If I uncomment those statements and comment out the return (matchFound), I get the same problem. The program eventually flows to the RETLW 00.
I'm using PCM v3.189.
--
Jeff S.
Code: | if (!matchFound) {
fprintf(DEBUGGER, "\nDid not match ");
fprintf(DEBUGGER, ATINFO.response);
fprintf(DEBUGGER, "\n");
//return FALSE; // Would just return matchFound, but there seems to be a bug in the compiler.
} else {
fprintf(DEBUGGER, "\nMatched ");
fprintf(DEBUGGER, ATINFO.response);
fprintf(DEBUGGER, "\n");
//return TRUE; // Would just return matchFound, but there seems to be a bug in the compiler.
}
return (matchFound); |
Code: | .................... if (!matchFound) {
*
09C8: BSF 03.6
09C9: BTFSC 56.0
09CA: GOTO 201
.................... fprintf(DEBUGGER, "\nDid not match ");
09CB: CLRF 57
09CC: MOVF 57,W
09CD: BCF 0A.3
09CE: BCF 03.6
09CF: CALL 087
09D0: BSF 0A.3
09D1: BSF 03.6
09D2: INCF 57,F
09D3: MOVWF 77
09D4: MOVWF 65
09D5: BCF 0A.3
09D6: BCF 03.6
09D7: CALL 320
09D8: BSF 0A.3
09D9: MOVLW 0F
09DA: BSF 03.6
09DB: SUBWF 57,W
09DC: BTFSS 03.2
09DD: GOTO 1CC
.................... fprintf(DEBUGGER, ATINFO.response);
09DE: MOVLW 63
09DF: MOVWF 04
09E0: BCF 03.7
09E1: MOVLW 00
09E2: IORWF 00,W
09E3: BTFSC 03.2
09E4: GOTO 1F9
09E5: CLRF 58
09E6: MOVF 04,W
09E7: MOVWF 57
09E8: BCF 58.0
09E9: BTFSC 03.7
09EA: BSF 58.0
09EB: MOVF 00,W
09EC: MOVWF 65
09ED: BCF 0A.3
09EE: BCF 03.6
09EF: CALL 320
09F0: BSF 0A.3
09F1: BSF 03.6
09F2: MOVF 57,W
09F3: MOVWF 04
09F4: BCF 03.7
09F5: BTFSC 58.0
09F6: BSF 03.7
09F7: INCF 04,F
09F8: GOTO 1E1
.................... fprintf(DEBUGGER, "\n");
09F9: MOVLW 0A
09FA: MOVWF 65
09FB: BCF 0A.3
09FC: BCF 03.6
09FD: CALL 320
09FE: BSF 0A.3
.................... //return FALSE; // Would just return matchFound, but there seems to be a bug in the compiler.
.................... } else {
09FF: GOTO 235
0A00: BSF 03.6
.................... fprintf(DEBUGGER, "\nMatched ");
0A01: CLRF 57
0A02: MOVF 57,W
0A03: BCF 0A.3
0A04: BCF 03.6
0A05: CALL 09B
0A06: BSF 0A.3
0A07: BSF 03.6
0A08: INCF 57,F
0A09: MOVWF 77
0A0A: MOVWF 65
0A0B: BCF 0A.3
0A0C: BCF 03.6
0A0D: CALL 320
0A0E: BSF 0A.3
0A0F: MOVLW 09
0A10: BSF 03.6
0A11: SUBWF 57,W
0A12: BTFSS 03.2
0A13: GOTO 202
.................... fprintf(DEBUGGER, ATINFO.response);
0A14: MOVLW 63
0A15: MOVWF 04
0A16: BCF 03.7
0A17: MOVLW 00
0A18: IORWF 00,W
0A19: BTFSC 03.2
0A1A: GOTO 22F
0A1B: CLRF 58
0A1C: MOVF 04,W
0A1D: MOVWF 57
0A1E: BCF 58.0
0A1F: BTFSC 03.7
0A20: BSF 58.0
0A21: MOVF 00,W
0A22: MOVWF 65
0A23: BCF 0A.3
0A24: BCF 03.6
0A25: CALL 320
0A26: BSF 0A.3
0A27: BSF 03.6
0A28: MOVF 57,W
0A29: MOVWF 04
0A2A: BCF 03.7
0A2B: BTFSC 58.0
0A2C: BSF 03.7
0A2D: INCF 04,F
0A2E: GOTO 217
.................... fprintf(DEBUGGER, "\n");
0A2F: MOVLW 0A
0A30: MOVWF 65
0A31: BCF 0A.3
0A32: BCF 03.6
0A33: CALL 320
0A34: BSF 0A.3
.................... //return TRUE; // Would just return matchFound, but there seems to be a bug in the compiler.
.................... }
.................... return (matchFound);
0A35: MOVLW 00
0A36: BSF 03.6
0A37: BTFSC 56.0
0A38: MOVLW 01
0A39: MOVWF 78
0A3A: GOTO 23B
.................... }
.................... }
0A3B: BCF 03.6
0A3C: RETLW 00 |
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Jun 04, 2004 10:09 am |
|
|
I thought that a return() (or return;) would break out of the function and not execute the remaining code of the function. If you un-comment the first two return's then the third one would never be executed. Plus, I think if you want to return a value you need to have return(value) stated. Just a simple 'return true;' or 'return false;' will simply return with no value being returned. You might want to change it to return(true); and return(false);. But, then again, if you do, the third return(matchFound) would not be executed.
Ronald |
|
|
William H. Conley III
Joined: 27 May 2004 Posts: 17 Location: Tucson, AZ
|
|
Posted: Fri Jun 04, 2004 10:20 am |
|
|
Try..........
if (!matchFound)
{
fprintf(DEBUGGER, "\nDid not match ");
fprintf(DEBUGGER, ATINFO.response);
fprintf(DEBUGGER, "\n");
return (FALSE);
}
else
{
fprintf(DEBUGGER, "\nMatched ");
fprintf(DEBUGGER, ATINFO.response);
fprintf(DEBUGGER, "\n");
return (TRUE);
}
return (matchFound); |
|
|
object01
Joined: 13 May 2004 Posts: 90 Location: Nashville, TN
|
|
Posted: Fri Jun 04, 2004 11:10 am |
|
|
Including the commented "return TRUE" and "return FALSE" statements results in the same problem. In fact, they cause the program to eventually flow to the same RETLW 00 statement. And parentheses around any of the return statements' parameters don't seem to affect it either. The assembly listing just keeps coming down to that RETLW 00 statement.
--
Jeff S. |
|
|
Guest
|
|
Posted: Fri Jun 04, 2004 11:25 am |
|
|
It has to be a bug? Your code is nothing I haven't used my self |
|
|
Guest
|
|
Posted: Sat Jun 05, 2004 11:57 am |
|
|
>> first, the instruction at 0xA3A, GOTO 23B, actually goes to 0xA3B.
This is the effect of ... 0A36: BSF 03.6
>> Second, the only return statement in any of this is the RETLW 00,
The return value is ... 0A39: MOVWF 78 ... CCS use RAM 0x78 for return value instead of the W.
read the SYM file:
078 @SCRATCH
078 _RETURN_
079 @SCRATCH
and read the LST file after the function call, there will be a line ... MOVF 78,W ... right after the CALL xxx. |
|
|
Ed Arnold
Joined: 02 Nov 2003 Posts: 18
|
same problem |
Posted: Sat Jun 05, 2004 1:20 pm |
|
|
I have had the same problem with my code. I ended up scraping the code. I am using version 3.148? Keep us posted with any new finding you may have. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|