Tomshao
Inactive
Offline
Posts: 3
Thank You
-Given: 2
-Receive: 0
|
|
« on: December 15, 2012, 01:15:58 13:15 » |
|
Hi guys,
I've been stucked for hours. It is a project for PIC16F1824, the compiler I am using is XC8 V1.12 in PRO mode.
Here is a segment of C code:
================================================================== case COMMAND_STATE_WAIT_DATALENGTH: Request.datalength = val; datacount++; if (Request.datalength>128) { *cmderr = COMMAND_ERROR_DATALENGTH; command_state = COMMAND_STATE_ABORT; } else if (Request.datalength ==0) { command_state = COMMAND_STATE_WAIT_CHECKSUM; } else { command_state = COMMAND_STATE_WAIT_DATA; }
break; ==========================================================
After compile,it turns into something like this:
! case COMMAND_STATE_WAIT_DATALENGTH: ! Request.datalength = val; 0x6B4: MOVF val, W 0x6B5: MOVWF 0x47 0x6B6: MOVLW 0x63 0x6B7: MOVWF FSR1L 0x6B8: MOVLW 0x20 0x6B9: MOVWF FSR1H 0x6BA: MOVF 0x47, W 0x6BB: MOVWF INDF1 ! datacount++; 0x6BD: INCF datacount, F ! if (Request.datalength>128) { 0x6BC: MOVLW 0x20 0x6BE: SUBWF INDF1, W 0x6BF: BTFSS STATUS, 0x0 0x6C0: GOTO 0x6C8 ! *cmderr = COMMAND_ERROR_DATALENGTH; 0x6C1: MOVF 0x52, W 0x6C2: MOVWF FSR1L 0x6C3: MOVLW 0x3 0x6C4: CLRF FSR1H 0x6C5: MOVWF INDF1 ! command_state = COMMAND_STATE_ABORT; 0x6C6: MOVLW 0x6 0x6C7: GOTO 0x70E ! } else if (Request.datalength ==0) { 0x6C8: MOVLW 0x62 0x6C9: MOVWF 0x47 ............................................
My question is, shouldn't the MOVLW 0x20(marked in red) be MOVLW 0x80?
After I change the compiler mode to "Free", the code works without any problem. However, the rom footprint of Free mode is so large and it has no pratical meaning for me.
Any suggestions? Your help will be greatly appreciated:
Posted on: December 15, 2012, 01:52:57 13:52 - Automerged
I changed "Request.datalength>128" to "Request.datalength+1>128+1", and it worked. >_<! what a miracle~~
|
|
|
Logged
|
|
|
|
sarah90
Active Member
Offline
Posts: 111
Thank You
-Given: 7
-Receive: 11
|
|
« Reply #1 on: December 16, 2012, 10:42:04 10:42 » |
|
What is the data type of Request.datalength? Looks like a problem related to signed/unsigned types.
|
|
|
Logged
|
|
|
|
Tomshao
Inactive
Offline
Posts: 3
Thank You
-Given: 2
-Receive: 0
|
|
« Reply #2 on: December 17, 2012, 05:52:19 17:52 » |
|
typedef unsigned char INT8U;
typedef struct _REQUEST { INT8U commandid; INT8U datalength; INT8U datafield[COMMAND_MAXIMUM_REQUESTLENGTH]; INT8U checksum; } REQUEST;
|
|
|
Logged
|
|
|
|
FTL
Junior Member
Offline
Posts: 83
Thank You
-Given: 170
-Receive: 33
|
|
« Reply #3 on: December 17, 2012, 10:42:52 22:42 » |
|
It certainly looks like a compiler bug from what you've shown.
What does the compiler generate if you change it from ">128" to ">64" or ">32"? The subtract with 0x20 implies a comparison with 32.
|
|
|
Logged
|
|
|
|
Tomshao
Inactive
Offline
Posts: 3
Thank You
-Given: 2
-Receive: 0
|
|
« Reply #4 on: December 18, 2012, 08:21:36 08:21 » |
|
After I changed 128 to 64, it yields: ........................................................................ ! datacount++; 0x6D5: INCF datacount, F ! //if (Request.datalength+1>COMMAND_MAXIMUM_REQUESTLENGTH) { ! if (Request.datalength>64) { 0x6D4: MOVLW 0x20 0x6D6: SUBWF INDF1, W 0x6D7: BTFSS STATUS, 0x0 0x6D8: GOTO 0x6E0 .......................................................................
After I changed it from 128 to 32 it yields: ...................................................................... ! datacount++; 0x6D5: INCF datacount, F ! //if (Request.datalength+1>COMMAND_MAXIMUM_REQUESTLENGTH) { ! if (Request.datalength>32) { 0x6D4: MOVLW 0x20 0x6D6: SUBWF INDF1, W 0x6D7: BTFSS STATUS, 0x0 0x6D8: GOTO 0x6E0 ......................................................................
It's quite weird and I agree with you, that may be some bug of the compiler.
|
|
|
Logged
|
|
|
|
FTL
Junior Member
Offline
Posts: 83
Thank You
-Given: 170
-Receive: 33
|
|
« Reply #5 on: December 18, 2012, 10:03:49 10:03 » |
|
That is amazingl You've given it 3 different comparison values, and it generated the same code! Clearly that is a bug. Fortunately you found a bypass with the +1 on each side. And I thought the CCS compilers were buggy with all the fixes they issue.
Maybe you should post this on the Microchip support forums and see what they think.
|
|
|
Logged
|
|
|
|
Gallymimu
Hero Member
Offline
Posts: 704
Thank You
-Given: 152
-Receive: 214
|
|
« Reply #6 on: December 19, 2012, 12:51:27 00:51 » |
|
Be sure to open a support ticket with Microchip in addition to putting it on the support forum. That way it is more likely to get logged into their system as a bug to fix.
If you give them the source code, and the compiler version they will definitely address it. Microchip is pretty good about working with people especially if they have bugs that the apps engineering can reproduce.
|
|
|
Logged
|
|
|
|
pickit2
Moderator
Hero Member
Offline
Posts: 4671
Thank You
-Given: 836
-Receive: 4331
There is no evidence that I muted SoNsIvRi
|
|
« Reply #7 on: December 19, 2012, 01:12:26 01:12 » |
|
Hi guys, After I change the compiler mode to "Free", the code works without any problem. However, the rom footprint of Free mode is so large and it has no pratical meaning for me.
Just read the topic.... if it works in free mode, and not in patched version, how can microchip, find the bug... If so, do you think they will help with the patching?
|
|
|
Logged
|
Note: I stoped Muteing bad members OK I now put thier account in sleep mode
|
|
|
Thiru09
Cracking Team
Senior Member
Offline
Posts: 328
Thank You
-Given: 395
-Receive: 1187
|
|
« Reply #8 on: December 19, 2012, 06:50:57 06:50 » |
|
if it works in free mode, and not in patched version, how can microchip, find the bug... May be this is the bug of PRO version's optimization section. Regards, Thiru
|
|
|
Logged
|
|
|
|
metal
Global Moderator
Hero Member
Offline
Posts: 2420
Thank You
-Given: 862
-Receive: 678
Top Topic Starter
|
|
« Reply #9 on: December 19, 2012, 10:42:19 10:42 » |
|
I still think you need to open a ticket @ microchip's site so that they fix it. I reported many bugs that are fixed now.
|
|
|
Logged
|
|
|
|
Gallymimu
Hero Member
Offline
Posts: 704
Thank You
-Given: 152
-Receive: 214
|
|
« Reply #10 on: December 19, 2012, 03:38:15 15:38 » |
|
I would suggest installing the "trial" version of the pro compiler, see if you get the same results, and then you will be in good shape with Microchip... There is a trial version of pro for XC8 right? It's been so long since I have installed it I can't remember.
|
|
|
Logged
|
|
|
|
Wannabe
Global Moderator
Senior Member
Offline
Posts: 430
Thank You
-Given: 228
-Receive: 285
|
|
« Reply #11 on: December 19, 2012, 09:59:25 21:59 » |
|
You can choose during installation to activate a 60 day PRO evaluation, and as far as I can tell the activation process doesn't send e-mail or any personal information. So just saying that you're in your evaluation period should be good. Happy bug-squashing
|
|
|
Logged
|
|
|
|
marcodassi
Junior Member
Warned
Offline
Posts: 40
Thank You
-Given: 73
-Receive: 26
|
|
« Reply #12 on: January 11, 2013, 01:59:03 01:59 » |
|
Yep... what a weird weird bug! Any news about it? Has Microchip been informed about that? Regards
|
|
|
Logged
|
|
|
|
|