Using preprocessor #define in asm

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Using preprocessor #define in asm

ソリューションへジャンプ
4,917件の閲覧回数
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,710件の閲覧回数
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,710件の閲覧回数
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,710件の閲覧回数
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,711件の閲覧回数
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,710件の閲覧回数
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 件の賞賛
返信