在扩展汇编器中划分浮点数
在我的 C 程序中,我想在扩展汇编程序中执行以下操作: 将两个浮点数(变量)“分子”除以“分母”,并将结果放入另一个变量“结果”中。这是我对它的外观的猜测,但它似乎无法编译。
float result, numerator, denominator;
asm volatile(" fdiv %2, %1 "
: "=r" (result)
: "1" (numerator), "2" (denominator));
编译错误:
example_program.c:66:16: error: matching constraint references invalid operand number
: "1" (numerator), "2" (denominator));
example_program:16: error: matching constraint references invalid operand number
example_program.c:64:3: error: matching constraint references invalid operand number
asm volatile(" fdiv %2, %1 "
^
example_program.c:64:3: error: matching constraint references invalid operand number
make: *** [<builtin>: example_program] Error 1
In my C program, I would like to do the following in extended assembler:
Divide two floating point numbers (variables), 'numerator' by 'denominator', and put the result in another variable, 'result'. This is my guess of how it would look like, but it does not seem to compile.
float result, numerator, denominator;
asm volatile(" fdiv %2, %1 "
: "=r" (result)
: "1" (numerator), "2" (denominator));
Compiling errors:
example_program.c:66:16: error: matching constraint references invalid operand number
: "1" (numerator), "2" (denominator));
example_program:16: error: matching constraint references invalid operand number
example_program.c:64:3: error: matching constraint references invalid operand number
asm volatile(" fdiv %2, %1 "
^
example_program.c:64:3: error: matching constraint references invalid operand number
make: *** [<builtin>: example_program] Error 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在进行任何内联汇编编程之前,请仔细阅读文档。 Gcc风格的内联汇编比较复杂并且容易出错。如果你弄错了,通常不会有错误。相反,错误的代码会默默地产生。因此,请确保您准确理解自己在做什么。就您而言,您应该特别关注 §6.47.2.9。
阅读本文档,以下代码似乎是正确的:
这允许源操作数是内存操作数。如果不需要,则语句可以更简单:
如果不将结果写入不同的变量,而是覆盖
分子
,则代码可以更简单。Before doing any inline assembly programming, read the documentation carefully. Gcc-style inline assembly is complicated and easy to get wrong. If you get it wrong, there is often no error. Instead, wrong code will silently be produced. So make sure you understand exactly what you are doing. In your case, you should especially focus on §6.47.2.9.
Reading this documentation, the following code seems correct:
This permits the source operand to be a memory operand. If that is not required, the statement can be simpler:
If instead of writing the result into a different variable, the
numerator
is to be overwritten, the code can be even simpler.