Using preprocessor #define in asm

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using preprocessor #define in asm

Jump to solution
3,979 Views
RValls
Contributor III

Hi everyone!

I am using project pannel "C/C++ Preprocessor" to #define global parameters of my project, and compile different code depending on them. It works fine in C files, but the problem is when I am using this parameter in an ASM source file, where I always get the error Unknown identifier.

I leave you an example:

 

/*In preprocessor pannel*/

#define MY_OPTION 1

 

/*In the *.s file*/

.extern MY_OPTION

 

#if MY_OPTION==1

  //Some code

#else

  //Some other code

 

How can I include this parameter to the asm file so when I compile the project, the compiler recognizes it?

 

Thanks in advance,

Rubén

Labels (1)
0 Kudos
1 Solution
772 Views
stanish
NXP Employee
NXP Employee

RValls,

 

You may use "Prefix file" option: "Alt+F7" -> "EPPC Assembler" -> "Prefix file" edit box.

If you create separate file for each target and add macro definitions into the files you can pass

these defs. into you asm file based on selected target.

 

Stanish

View solution in original post

0 Kudos
4 Replies
772 Views
stanish
NXP Employee
NXP Employee

Hello RValls,

 

You can try to create separate .h file and include this file in your .asm files. e.g:

 

/* mydefs.h */

#define MY_OPTION 1

 

 

/* asm file */

 

#include "mydefs.h"

#if MY_OPTION==1

  //Some code

....

#endif

 

0 Kudos
772 Views
RValls
Contributor III

Hi again, and thanks for the fast reply.

 

That works fine, but I'm still having a problem: I am using different targets to use one code or other code, or one processor or other, etc... and I want to mantein this easy way of changing from one to other, so the solution of using an options.h file is not usefull, because if I change this file from MY_OPTION 1 to MY_OPTION 0, it will also be changed in the other targets.

 

Any other solution?

 

Thanks,

Rubén

0 Kudos
773 Views
stanish
NXP Employee
NXP Employee

RValls,

 

You may use "Prefix file" option: "Alt+F7" -> "EPPC Assembler" -> "Prefix file" edit box.

If you create separate file for each target and add macro definitions into the files you can pass

these defs. into you asm file based on selected target.

 

Stanish

0 Kudos
772 Views
RValls
Contributor III

Thank you very much! That was exactly what I need, now it goes fine just by changing the target!

I have marked the post as Solved. 

 

Thanks again, stanish

 

Rubén

0 Kudos