【问题标题】:How to emit floating point immediate operand using decimal representation in gnu assembler如何在 gnu 汇编器中使用十进制表示发出浮点立即操作数
【发布时间】:2017-06-22 05:47:48
【问题描述】:

例如,0.5f 在目标平台中为 0x3F000000。我想使用movl $0.5,%eax 之类的东西,而不是movl $0x3F000000,%eax

汇编程序来自 TDM-GCC。

【问题讨论】:

    标签: gcc assembly x86 floating-point gnu-assembler


    【解决方案1】:

    您需要使用.float, .single or .double directives 声明一个单独的常量

    例如

    .data
            half: .float 0.50
    .text
    .globl _start
            _start:
            movl half, %eax
    

    https://en.wikibooks.org/wiki/X86_Assembly/AVX,_AVX2,_FMA3,_FMA4

    您还可以在inline assembly 中使用 E/F/G/H 约束

    static const float half = 0.5f;
    __asm__ __volatile__ ("\n\
       movl %1, %eax        %1"
       : "g" (half)
       ) ;
    

    【讨论】:

    • 前者实际上是插入一个立即,还是从.data部分加载一个值?
    • 它从内存中加载一个值。我还没有找到插入立即数的方法
    猜你喜欢
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多