如何指定用内联汇编直接浮点数? [英] How do I specify immediate floating point numbers with inline assembly?

查看:188
本文介绍了如何指定用内联汇编直接浮点数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译此code:

When I try to compile this code:

#include <stdio.h>

main(int argc, char *argv[]) {
   double y = 0;

   __asm__ ("fldl $150;"
            "fsqrt;"
            "fstl %0;" : : "g" (y) );

   printf("%f\n", y);


   return 0;
}

我得到这个错误:

I get this error:

sqrt.c: Assembler messages:
sqrt.c:6: Error: suffix or operands invalid for `fld'

为什么不工作的呢?为什么我不能推数字150到堆栈中的浮点运算?

Why doesn't this work? Why can't I push the number "150" onto the stack for floating point operations?

推荐答案

我不知道它支持立即使用字面浮点常量的汇编语言。通常的方法是声明包含浮点常量和引用它初始化存储:

I do not know of an assembly language which supports literal floating point constants for immediate use. The usual means is to declare initialized storage containing the floating point constant and referencing it:

const1:     dq  1.2345
...
     fldl    const1

有关你给的例子,可以更直接地做到这一点:

For the example you give, it is possible to do this more directly:

printf ("%f\n", sqrt (150));

否则,这必须是一个人为的复杂的工程,也许功课。

Otherwise, this must be an artificially complicated project, perhaps homework.

这篇关于如何指定用内联汇编直接浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆