简体   繁体   English

预处理程序不跳过asm指令

[英]Preprocessor not skipping asm directives

I'm programming to a microprocessor (Coldfire) and I don't have access every day to the microprocessor trainer so I want to be able to execute some of my code on the computer. 我正在使用微处理器(Coldfire)进行编程,而我每天都无法访问微处理器培训师,因此我希望能够在计算机上执行一些代码。

So I'm trying to skip a part of my code when executing on the computer by defining TEST . 所以我试图通过定义TEST在计算机上执行时跳过部分代码。

It doesn't work. 没用 It tries to compile the asm code and dies whining about not knowing the registers names (they're defined alright compiling against the Coldfire, not my Intel Core Duo). 它试图编译asm代码,并因不知道寄存器名称而死(他们被定义为可以根据Coldfire而不是我的Intel Core Duo进行编译)。

Any ideas why it's not working? 任何想法为什么它不起作用? or maybe an alternative way to run the code on the pc without commenting it out?. 还是一种无需注释即可在PC上运行代码的替代方法?

Here's sample code from my project: 这是我的项目中的示例代码:


inline void ct_sistem_exit(int status)
{
#ifdef _TEST_
    exit(status);
#else
    asm volatile(
            "moveb #0,%%d1\n\t"
            "movel #0, %%d0\n\t"
            "trap #15\n\t"
            :
            :
            : "d0", "d1"
            );
#endif /* _TEST_ */
}

If it helps: using gcc3 with cygwin on Netbeans 6.8 如果有帮助:在Netbeans 6.8上将gcc3与cygwin一起使用

And the way I'm defining _TEST_: 以及我定义_TEST_的方式:



#define _TEST_
#include "mycode.c"

int main(int argc, char** argv)
{
    ct_sistem_exit(0);
}

The obvious question is did you define _TEST_ ? 显而易见的问题是您定义了_TEST_吗? You can do it on the command line with -D_TEST_ . 您可以在命令行上使用-D_TEST_

I can compile your code when I define it. 我可以在定义代码时对其进行编译。

You normally shouldn't use symbol names that start with the underscore. 通常,您不应该使用以下划线开头的符号名称。 Those are reserved for use by the compiler and standard libraries. 这些保留供编译器和标准库使用。 It is likely that there is already a TEST defined somewhere. 可能已经在某处定义了一个TEST It should be easy enough to check for, though. 不过,它应该很容易检查。

You may want to try using #warning to tell you when you are building for the test machine, which will help you test that the preprocessor is doing what you expect. 您可能想尝试使用#warning告诉您何时为测试机构建,这将帮助您测试预处理器是否按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM