CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PCM 3.059: Array Indexing Generates Bad Machine Code?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Paul Klissner
Guest







PCM 3.059: Array Indexing Generates Bad Machine Code?
PostPosted: Sun Nov 18, 2001 6:02 pm     Reply with quote

I'm developing code for the 16F628.
Tthe following is the chip configuration I'm using:

#fuses INTRC_IO,NOWDT,NOLVP,MCLR,NOPROTECT,NOPUT,NOBROWNOUT

setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_vref(FALSE);
setup_comparator(NC_NC_NC_NC);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);

I've written an program that declares some arrays as follows:

long int list0[4],list1[4],ix0[3],ix1[3];

Later in the code after performing many tasks, when
referring to the arrays the processor resets expectedly:

if (++ix0[n] < list0[n] ||
ix0[n] >= (list0[n+1]-3)) {

Reset seems to occur array access via the index
(regardless of whether n is declared byte, char or int).

In order to see instruction it was resetting on, I compiled
it and extracted the assembly code from the listing file.
I commented out the GOTO statements since this tampering could
easily make them jump to the wrong places.

Through commenting and the process of elimination
I disovered it resets on the second MOVWF 0x20 as
indicated below. Any ideas why this might be happening?


#ASM
BCF 03.0
RLF 0x46,W
MOVWF 0x20 //GENERAL DATA AREA
ADDLW 0x35
MOVWF 0x04 //FSR
INCF 0x00,F
BTFSS 0x03.2
//GOTO 0x3F7
INCF 0x04,F //FSR
INCF 0x00,F //INDF
BCF 0x03.0
RLF 0x46,W
MOVWF 0x20 <======== PROCESSOR RESETS HERE
ADDLW 0x25
MOVWF 0x04
INCF 0x04,F
MOVF 0x00,W
MOVWF 0x23
DECF 0x04,F
MOVF 0x00,W
MOVWF 0x21
INCF 0x04,F
MOVF 0x00,W
SUBWF 0x23,W
BTFSS 0x03.0
//GOTO 0x40E
BTFSS 0x03.2
GOTO 0x43C
DECF 0x04,F
MOVF 0x21,W
SUBWF 0x00,W
BTFSS 0x03.0
//GOTO 0x43C
BCF 0x03.0
RLF 0x46,W
MOVWF 0x20
ADDLW 0x35
MOVWF 0x04
INCF 0x04,F
MOVF 0x00,W
MOVWF 0x49
DECF 0x04,F
MOVF 0x00,W
MOVWF 0x48
MOVLW 0x01
ADDWF 0x46,W
MOVWF 0x20
BCF 0x03.0
RLF 0x20,F
MOVF 0x20,W
ADDLW 0x25
MOVWF 0x04
INCF 0x04,F
MOVF 0x00,W
MOVWF 0x4C
DECF 0x04,F
MOVF 00,W
MOVWF 0x4B
MOVLW 0x03
SUBWF 0x4B,W
MOVWF 0x20
MOVF 0x4C,W
MOVWF 0x23
MOVLW 0x00
BTFSS 0x03.0
MOVLW 0x01
SUBWF 0x23,F
MOVF 0x20,W
MOVWF 0x21
MOVF 0x23,W
SUBWF 0x49,W
BTFSS 0x03.0
//GOTO 0x460
BTFSS 0x03.2
//GOTO 0x43C
MOVF 0x21,W
SUBWF 0x48,W
BTFSS 0x03.0
//GOTO 0x460
/**/
#ENDASM
___________________________
This message was ported from CCS's old forum
Original Post ID: 1206
Paul Klissner
Guest







Re: PCM 3.059: Array Indexing Generates Bad Machine Code?
PostPosted: Sun Nov 18, 2001 7:03 pm     Reply with quote

After thinking about the code a bit more, it sure didn't seem
to be a bug in the compiler generated code. Sorry. You know
how frustrating these things can be...

It seems like it is just automatically resetting approximately
that many instructions in, and doesn't seem to matter what the
statement is.

Still confused as to the possible causes.
-Paul


:=I'm developing code for the 16F628.
:=Tthe following is the chip configuration I'm using:
:=
:=#fuses INTRC_IO,NOWDT,NOLVP,MCLR,NOPROTECT,NOPUT,NOBROWNOUT
:=
:= setup_timer_1(T1_DISABLED);
:= setup_timer_2(T2_DISABLED,0,1);
:= setup_ccp1(CCP_OFF);
:= setup_ccp2(CCP_OFF);
:= setup_vref(FALSE);
:= setup_comparator(NC_NC_NC_NC);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=
:=I've written an program that declares some arrays as follows:
:=
:= long int list0[4],list1[4],ix0[3],ix1[3];
:=
:=Later in the code after performing many tasks, when
:=referring to the arrays the processor resets expectedly:
:=
:= if (++ix0[n] < list0[n] ||
:= ix0[n] >= (list0[n+1]-3)) {
:=
:=Reset seems to occur array access via the index
:=(regardless of whether n is declared byte, char or int).
:=
:=In order to see instruction it was resetting on, I compiled
:=it and extracted the assembly code from the listing file.
:=I commented out the GOTO statements since this tampering could
:=easily make them jump to the wrong places.
:=
:=Through commenting and the process of elimination
:=I disovered it resets on the second MOVWF 0x20 as
:=indicated below. Any ideas why this might be happening?
:=
:=
:=#ASM
:=BCF 03.0
:=RLF 0x46,W
:=MOVWF 0x20 //GENERAL DATA AREA
:=ADDLW 0x35
:=MOVWF 0x04 //FSR
:=INCF 0x00,F
___________________________
This message was ported from CCS's old forum
Original Post ID: 1211
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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