预处理器不跳过 asm 指令
我正在对微处理器(Coldfire)进行编程,但我无法每天访问微处理器训练器,因此我希望能够在计算机上执行一些代码。
因此,我试图通过定义TEST在计算机上执行时跳过部分代码。
这不起作用。它尝试编译 asm 代码,然后因不知道寄存器名称而死掉(它们是针对 Coldfire 编译的,而不是我的 Intel Core Duo)。
有什么想法为什么它不起作用吗?或者也许有另一种方法可以在电脑上运行代码而无需注释掉它?
这是我的项目中的示例代码:
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_ */
}
如果有帮助:在 Netbeans 6.8 上使用 gcc3 和 cygwin
我定义_TEST_的方式:
#define _TEST_
#include "mycode.c"
int main(int argc, char** argv)
{
ct_sistem_exit(0);
}
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.
So I'm trying to skip a part of my code when executing on the computer by defining 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).
Any ideas why it's not working? or maybe an alternative way to run the code on the pc without commenting it out?.
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
And the way I'm defining _TEST_:
#define _TEST_
#include "mycode.c"
int main(int argc, char** argv)
{
ct_sistem_exit(0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明显的问题是您定义了
_TEST_
吗?您可以使用-D_TEST_
在命令行上执行此操作。当我定义它时我可以编译你的代码。
The obvious question is did you define
_TEST_
? You can do it on the command line with-D_TEST_
.I can compile your code when I define it.
通常不应使用以下划线开头的符号名称。这些保留供编译器和标准库使用。很可能已经在某处定义了一个TEST。不过,检查起来应该很容易。
您可能想尝试使用#warning 来告诉您何时为测试机器进行构建,这将帮助您测试预处理器是否正在执行您期望的操作。
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. 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.