Hi guys, Here is my post of the day! I've got a main function implemented in C, in which i call in particular an asm function. In my c program i define a constant. Now i want to use it in the asm function. To acheive this, i thought i could use the .ref directive since my constant is defined in another module than the asm function. But when i build my project, i've got the following error : "symbol referencing error". So i wonder if it's possible to use a constant in a asm function if this constant has been defined in a C function. If it is, what i can do not to have this error? Is there another way to do it? Thanks again to everyone.
A simple question (definition of a constant with TMS320VC5402)
Started by ●July 13, 2004
Reply by ●July 13, 20042004-07-13
phuture_project wrote:> Hi guys, > > Here is my post of the day! > > I've got a main function implemented in C, in which i call in > particular an asm function. In my c program i define a constant. Now i > want to use it in the asm function. To acheive this, i thought i could > use the .ref directive since my constant is defined in another module > than the asm function. But when i build my project, i've got the > following error : "symbol referencing error". > > So i wonder if it's possible to use a constant in a asm function if > this constant has been defined in a C function. If it is, what i can > do not to have this error? > > Is there another way to do it? > > Thanks again to everyone.Use the linker map to find it's location and fetch it from there. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●July 13, 20042004-07-13
phuture_project wrote:> Hi guys, > > Here is my post of the day! > > I've got a main function implemented in C, in which i call in > particular an asm function. In my c program i define a constant. Now i > want to use it in the asm function. To acheive this, i thought i could > use the .ref directive since my constant is defined in another module > than the asm function. But when i build my project, i've got the > following error : "symbol referencing error". > > So i wonder if it's possible to use a constant in a asm function if > this constant has been defined in a C function. If it is, what i can > do not to have this error? > > Is there another way to do it? > > Thanks again to everyone.How are you defining the constant? If you are using #define then the definition is entirely lexical and never escapes the compilation. If you use "const int bob = 23;" or some such then it should be available externally. C compilers traditionally tag C variables with a special character, usually an underline. This means that if the variable is named 'bob' in C then it is very likely '_bob' in assembly. I can't remember what Code Composter does to variables in C, so do this test: Try compiling to assembly, and looking at your compiler output -- you should be able to see the name of the constant in assembler-land. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●July 14, 20042004-07-14
Tim Wescott <tim@wescottnospamdesign.com> wrote in message news:<10f8165cvdlqk7c@corp.supernews.com>...> phuture_project wrote: > > > Hi guys, > > > > Here is my post of the day! > > > > I've got a main function implemented in C, in which i call in > > particular an asm function. In my c program i define a constant. Now i > > want to use it in the asm function. To acheive this, i thought i could > > use the .ref directive since my constant is defined in another module > > than the asm function. But when i build my project, i've got the > > following error : "symbol referencing error". > > > > So i wonder if it's possible to use a constant in a asm function if > > this constant has been defined in a C function. If it is, what i can > > do not to have this error? > > > > Is there another way to do it? > > > > Thanks again to everyone. > > How are you defining the constant? If you are using #define then the > definition is entirely lexical and never escapes the compilation. If > you use "const int bob = 23;" or some such then it should be available > externally. C compilers traditionally tag C variables with a special > character, usually an underline. This means that if the variable is > named 'bob' in C then it is very likely '_bob' in assembly. > > I can't remember what Code Composter does to variables in C, so do this > test: Try compiling to assembly, and looking at your compiler output -- > you should be able to see the name of the constant in assembler-land.If I remember correctly, the bob variable will be in .const section.. Take a look at the map file... There is a serious discussion before whether to use const/#define in C code.. When I worked with CCS before, the CCS optimizer did generate wrong code with const.. So, just be careful.. In general, the practice is to use constant.. It provides the following checking for you: - Type checking.. - Shorter compiler make cycle.. It is better than a #define.. It normally will affect many files.. GoodLuck Arthur
Reply by ●July 14, 20042004-07-14
Arthur wrote:> Tim Wescott <tim@wescottnospamdesign.com> wrote in message news:<10f8165cvdlqk7c@corp.supernews.com>... > >>phuture_project wrote: >> >> >>>Hi guys, >>> >>>Here is my post of the day! >>> >>>I've got a main function implemented in C, in which i call in >>>particular an asm function. In my c program i define a constant. Now i >>>want to use it in the asm function. To acheive this, i thought i could >>>use the .ref directive since my constant is defined in another module >>>than the asm function. But when i build my project, i've got the >>>following error : "symbol referencing error". >>> >>>So i wonder if it's possible to use a constant in a asm function if >>>this constant has been defined in a C function. If it is, what i can >>>do not to have this error? >>> >>>Is there another way to do it? >>> >>>Thanks again to everyone. >> >>How are you defining the constant? If you are using #define then the >>definition is entirely lexical and never escapes the compilation. If >>you use "const int bob = 23;" or some such then it should be available >>externally. C compilers traditionally tag C variables with a special >>character, usually an underline. This means that if the variable is >>named 'bob' in C then it is very likely '_bob' in assembly. >> >>I can't remember what Code Composter does to variables in C, so do this >>test: Try compiling to assembly, and looking at your compiler output -- >>you should be able to see the name of the constant in assembler-land. > > > If I remember correctly, the bob variable will be in .const section.. > Take a look at the map file... > > There is a serious discussion before whether to use const/#define in C > code.. When I worked with CCS before, the CCS optimizer did generate > wrong code with const.. So, just be careful.. > > In general, the practice is to use constant.. It provides the > following checking for you: > - Type checking.. > - Shorter compiler make cycle.. It is better than a #define.. It > normally will affect many files.. > > GoodLuck > ArthurA good optimizing compiler will take a known 'const' declaration and just use the constant if it's faster, and if it isn't declared as 'volatile const'. If it's not declared static then it should also put a copy in the .const section of memory so you can access it if you know the C to assembly naming conventions for you particular compiler. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●July 15, 20042004-07-15
Hi Jerry,> Use the linker map to find it's location and fetch it from there.You mean to search for the adress in which is stored the constant and then to recover it, don't you? I thought of it. The issue is that if i add a line code in my program this adress will surely change. So i'll have to search for it once again, am i wrong? I'd rather use anotehr way, if possible. Thanks.
Reply by ●July 15, 20042004-07-15
Hi Tim,> How are you defining the constant? If you are using #define then the > definition is entirely lexical and never escapes the compilation. If > you use "const int bob = 23;" or some such then it should be available > externally. C compilers traditionally tag C variables with a special > character, usually an underline. This means that if the variable is > named 'bob' in C then it is very likely '_bob' in assembly. >I tried some things from what you suggested and what seemed to work was to do the following things: - declare the constant in C like : const int toz=100; - and in the assembler prog to make : .ref _toz It seemed to work since the error ("symbol referencing errors") disappeared and since the program seemed to work properly. But in fact another issue appeared. To be clearer, here is what i'm doing. In my main c function, i make all the intializations and then comes the following loop : do { SampleLoop(x); } while(1); The function called "SampleLoop" is the assembler function. It makes reference to the constant called n_sample (as "toz" in the precedent lines). This function allows to recover samples and store them in a table. The table is defined as "unsigned int x[500];". The value of n_sample is 500, i use it to stop the sample loop when the "location" x[500] has been reached. (I hope this is clear enough. It's late, so i'm a little tired now! ;:) ) So i just remarked that if i don't use n_sample the table x[] is entirely filled. Whereas if i use n_sample, only the 128 first "locations" are filled. It looks strange isn't it? Of course i could avoid employing the constant n_sample. But i'd like to know why this issue appears?! Thanks.
Reply by ●July 15, 20042004-07-15
> If I remember correctly, the bob variable will be in .const section.. > Take a look at the map file... > > There is a serious discussion before whether to use const/#define in C > code.. When I worked with CCS before, the CCS optimizer did generate > wrong code with const.. So, just be careful.. > > In general, the practice is to use constant.. It provides the > following checking for you: > - Type checking.. > - Shorter compiler make cycle.. It is better than a #define.. It > normally will affect many files.. > > GoodLuck > ArthurThank you arthur.
Reply by ●July 15, 20042004-07-15
phuture_project wrote:> Hi Jerry, > > >>Use the linker map to find it's location and fetch it from there. > > > You mean to search for the adress in which is stored the constant and > then to recover it, don't you? > I thought of it. The issue is that if i add a line code in my program > this adress will surely change. So i'll have to search for it once > again, am i wrong? I'd rather use anotehr way, if possible. > > Thanks.There is usually a way to have a symbolic address (label). That will be in the linker map too. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●July 15, 20042004-07-15
phuture_project wrote:> Hi Tim, > > >>How are you defining the constant? If you are using #define then the >>definition is entirely lexical and never escapes the compilation. If >>you use "const int bob = 23;" or some such then it should be available >>externally. C compilers traditionally tag C variables with a special >>character, usually an underline. This means that if the variable is >>named 'bob' in C then it is very likely '_bob' in assembly. >> > > > I tried some things from what you suggested and what seemed to work > was to do the following things: > > - declare the constant in C like : const int toz=100; > - and in the assembler prog to make : .ref _toz > > It seemed to work since the error ("symbol referencing errors") > disappeared and since the program seemed to work properly. > But in fact another issue appeared. > > To be clearer, here is what i'm doing. > > In my main c function, i make all the intializations and then comes > the following loop : > > do > { > SampleLoop(x); > } > while(1); > > The function called "SampleLoop" is the assembler function. It makes > reference to the constant called n_sample (as "toz" in the precedent > lines). > This function allows to recover samples and store them in a table. The > table is defined as "unsigned int x[500];". The value of n_sample is > 500, i use it to stop the sample loop when the "location" x[500] has > been reached. (I hope this is clear enough. It's late, so i'm a little > tired now! ;:) ) > So i just remarked that if i don't use n_sample the table x[] is > entirely filled. Whereas if i use n_sample, only the 128 first > "locations" are filled. It looks strange isn't it? > > Of course i could avoid employing the constant n_sample. But i'd like > to know why this issue appears?! > > Thanks.It would appear to be a bug in how you compare on n_sample. Get some sleep and try again! You might also consider passing n_sample to the SampleLoop in the function call. This will increase your overhead slightly compared to whatever multiple of 500 clock cycles you're using up in SampleLoop, but it will make your code more portable, and it will make the linkages clearer. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com






