cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with compiler

pbrea
Associate II
Posted on August 24, 2005 at 09:34

Problem with compiler

14 REPLIES 14
pbrea
Associate II
Posted on August 22, 2005 at 08:36

Hi!

I'm using an ST72F264 and I'm programming in C with Metrowerks Codewarrior version 4.2.5.766.

I'm writing this instruction:

for(i=0;i

{buff_data[i]=buff_rx[i+6];}

where i is a local variable and data_lenght, buff_data[], buff_tx[] are declared in the file var.h that is included in main.c with:

#include ''var.h''

When I debug with ST7 Visual Debug inDART-STX v.2.02 based on STVD 2.5.3, I receive this message from the output window:

Program received signal SIGTRAP, Trace/breakpoint trap.

_Startup () at START07.C:84

84 RSP

and the debug is stopped.

If I modify the C code in:

j=data_lenght;

for(i=0;(!((j-i)==0));i++)

{buff_data[i]=buff_rx[i+6];}

where i,j are local variables and buff_data[], buff_tx[] are declared in the file var.h, all works correctly.

The disassembly window in the first case is:

for(i=0;i

0xf6fb 0x3FB9 CLR i

0xf6fd 0x2002 JRT 0xf701

buff_data[i]=buff_rx[i+6];

0xf6ff 0xAD6B CALLR 0xf76c

for(i=0;i

0xf701 0xB6B9 LD A,i

0xf703 0x9097 LD Y,A

0xf705 0x5F CLR X

0xf706 0x4F CLR A

0xf707 0xCDFF1C CALL _CMPS

0xf70a 0x25F3 JRC 0xf6ff

0xf70c 0x2607 JRNE 0xf715

0xf70e 0x909F LD A,Y

0xf710 0xC1013A CP A,0x013a

0xf713 0x25EA JRC 0xf6ff

while in the second case:

j=data_lenght_ind;

0xf6bf 0xC6013A LD A,0x013a

0xf6c2 0xB7BA LD j,A

for(i=0;(!((j-i)==0));i++)

0xf6c4 0x3FB9 CLR i

0xf6c6 0x2003 JRT 0xf6cb

buff_data[i]=buff_rx[i+6];

0xf6c8 0xCDF76C CALL 0xf76c

for(i=0;(!((j-i)==0));i++)

0xf6cb 0xB6BA LD A,j

0xf6cd 0xBEB9 LD X,i

0xf6cf 0xB0B9 SUB A,i

0xf6d1 0xB7B8 LD _spill_1,A

0xf6d3 0x4F CLR A

0xf6d4 0xA200 SBC A,#0x00

0xf6d6 0xBAB8 OR A,_spill_1

0xf6d8 0x26EE JRNE 0xf6c8

I noted that all the problems are resolved if the function _CMPS called at address 0xf707 in the first case is not used.

Can you help me?

My main.prm file is:

NAMES

END

SECTIONS

MY_ZRAM = NO_INIT 0x0080 TO 0x00c5;

MY_RAM = READ_WRITE 0x00c6 TO 0x14f;

MY_ROM = READ_ONLY 0xF000 TO 0xFFDF;

PLACEMENT

DEFAULT_ROM, ROM_VAR, STRINGS INTO MY_ROM;

_ZEROPAGE, DEFAULT_RAM INTO MY_RAM;

_OVERLAP INTO MY_ZRAM;

END

STACKTOP 0x17F

VECTOR ADDRESS 0xFFFE _Startup

VECTOR ADDRESS 0xFFF2 INT_TIMER_A

VECTOR ADDRESS 0xFFF0 REAL_TIME

Thanks.

wolfgang2399
Associate II
Posted on August 22, 2005 at 11:06

Hi,

the first instruction doesn't make a sense to me. Think, there's something missing in your description.

Also I can't understand the compiler result. If I apply the Metroworks compiler to your first instruction I get some error messages on the syntax....

WoRo

pbrea
Associate II
Posted on August 22, 2005 at 11:17

Excuse me!

There is a syntax error in the text. The correct instruction is:

for(i=0;i <data_lenght;i++)

{

buff_data[i]=buff_rx[i+6];

}

Thanks.

wolfgang2399
Associate II
Posted on August 22, 2005 at 12:54

Hi,

although I can't reproduce your error - it is good programming style to define variables like 'i' and 'data_length' as 'unsigned ...'. Using 'unsigned char' would prevent the compiler from calling the function _CMPS which is a signed comparison function.

WoRo

pbrea
Associate II
Posted on August 22, 2005 at 13:43

Thanks for the informations but all variables are declared as unsigned char . If I do a cast to unsigned char before the 'for' instruction the result is the same and the problem is not resolved too.

Hi

wolfgang2399
Associate II
Posted on August 23, 2005 at 07:11

When I feed the compiler with your instruction I get the list file following:

--source:------------------------------------------------------------

extern unsigned char data_lenght;

extern int buff_data[],buff_rx[];

void func(void)

{

unsigned char i;

for(i=0;i

{

buff_data[i]=buff_rx[i+6];

}

};

---.lst:-----------------------------------------------------------

ANSI-C/cC++ Compiler for ST7 V-5.0.7, Aug 21 2001

1: extern unsigned char data_lenght;

2: extern int buff_data[],buff_rx[];

3:

4:

5: void func(void)

6: {

Function: func

Source : E:\Project\C_Prog\sources\Test2.C

Options : -Cc -Cni -Cq -CswMinLF80 -CswMinSLB10 .....

7: unsigned char i;

8: for(i=0;i

0000 3f00 CLR i

0002 2037 JRT *57 ;abs = 003b

9: {

10: buff_data[i]=buff_rx[i+6];

0004 b600 LD A,i

0006 9097 LD Y,A

0008 ab06 ADD A,#6

000a 97 LD X,A

000b a602 LD A,#2

000d 42 MUL X,A

000e ab00 ADD A,#buff_rx

0010 b701 LD _LEX:1,A

0012 9f LD A,X

0013 a901 ADC A,#HIGH(buff_rx)

0015 b700 LD _LEX,A

0017 909f LD A,Y

0019 48 SLL A

001a 97 LD X,A

001b 4f CLR A

001c 49 RLC A

001d 9097 LD Y,A

001f 9f LD A,X

0020 ab00 ADD A,#buff_data

0022 b701 LD _SEX:1,A

0024 909f LD A,Y

0026 a901 ADC A,#HIGH(buff_data)

0028 ae01 LD X,#1

002a b700 LD _SEX,A

002c 92d600 LD A,([_LEX.w],X)

002f 92d700 LD ([_SEX.w],X),A

0032 92ce00 LD X,[_LEX.w]

0035 9f LD A,X

0036 92c700 LD [_SEX.w],A

0039 3c00 INC i

003b b600 LD A,i

003d c10000 CP A,data_lenght

0040 25c2 JRULT *-60 ;abs = 0004

11: }

12: };

0042 81 RET

--------------------------------------------------------

Find it's perfect...

In my attemps I only get the _CMPS function when 'i' and 'data_lenght' both are signed char.

To find the difference to your result it would be helpfull you post the special cut-out of the ~.lst file. And please give us the option-part oft the option-line (e.g. Options : -Cc -Cni -Cq -CswMinLF80 -CswMinSLB10 .....).

Greetings

WoRo

wolfgang2399
Associate II
Posted on August 23, 2005 at 07:32

Whoops - :o - I see, that the text has been scrambled by the text-system of this forum.

Therefore I'll attach the relevant C-source and the compiled text in a .txt-file to this message.

WoRo

________________

Attachments :

test.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Ci&d=%2Fa%2F0X0000000bVH%2FBJWUQz5GkhcnKGHV6RobQHUWbca7AS58cUQeC3k2X6g&asPdf=false
pbrea
Associate II
Posted on August 23, 2005 at 14:33

Hi,

the only option-part I have regards the memory model and is:

-Ml (large memory model)

I don't have the ~.lst file because I use a previous version of the compiler.

I only have a ~.map file and others ~.o files.

Thanks

wolfgang2399
Associate II
Posted on August 24, 2005 at 07:24

Hi again,

I am using exactly the same version as you of the MetroWerks CodeWarrior and can get ~.lst-files.

To get them you have to set the option 'Generate Listing File' of the compiler:

Follow the menue

Edit & ''project'' Settings [Alt+F7] & Compiler for ST7 -

and then select

Options & Output & [x] Generate Listing File

You will find the ~.lst-file in the bin-folder when compiled.

BUT...: As you have got the disambly window, there is all the information you/I need. Only the text has been scrambled by the text-converter of this forum - but that should be no problem any more.

Anyway, studying your disambly window again and again I come to the conclusion, that the type of 'i' or/and 'data_lenght' can not be 'unsigned char' at the time it is used there. Please recheck your code thoroughly.

Greetings

WoRo