Using preprocessor #define in asm

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Using preprocessor #define in asm

跳至解决方案
4,914 次查看
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

标签 (1)
0 项奖励
回复
1 解答
1,707 次查看
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 项奖励
回复
4 回复数
1,707 次查看
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 项奖励
回复
1,707 次查看
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 项奖励
回复
1,708 次查看
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 项奖励
回复
1,707 次查看
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 项奖励
回复