【问题标题】:GCC inline assembly error: asm-specifier for variable '%al' conflicts with asm clobber listGCC 内联汇编错误:变量 '%al' 的 asm 说明符与 asm clobber 列表冲突
【发布时间】:2011-06-02 06:22:37
【问题描述】:

很抱歉有这么多问题,但我在尝试编译以下在 MSVC 中工作的内联程序集(使用 -fasm-blocks)时遇到了另一个神秘错误,但显然不在 GCC 中并且无法处理:

unsigned char testData = 128;

__asm
{
    // ...
    mov al, testData
    mov ah, al // error: asm-specifier for variable '%al' conflicts with asm clobber list
    shl eax, 16
    // ...
};


这个 clobber 列表 是什么?它有什么问题?

我也尝试过更改优化级别,但没有效果。

【问题讨论】:

    标签: c++ visual-c++ gcc assembly inline-assembly


    【解决方案1】:

    这一定是 gcc 中的一些错误(可能 __asm 块有隐式破坏)。无论如何,有很多解决方法:

    __asm
    {
        // ...
        mov ah, testData
        mov al, ah
        shl eax, 16
        // ...
    };
    

    或

    __asm
    {
        // ...
        mov al, testData
        mov ah, testData
        shl eax, 16
        // ...
    };
    

    或

    __asm
    {
        // ...
        movzx eax, testData
        imul eax, 0x0101
        shl eax, 16
        // ...
    };
    

    【讨论】:

      【解决方案2】:

      clobber-list 在这里解释:http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html,但不是在你的 __asm 语法的上下文中,我不熟悉。试图编译你的 sn-p 我得到了

      jcomeau@intrepid:/tmp$ make test
      cc     test.c   -o test
      test.c:4: error: expected ‘(’ before ‘{’ token
      

      【讨论】:

      • 这是 Apple 独有的选项吗? Linux 上的 gcc 无法识别它
      • 是的,它是苹果独有的,而且有些漏洞。此外,它会为隐式破坏寄存器保存带来严重的性能损失。
      猜你喜欢
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多