开发者

GCC inline assembly error: asm-specifier for variable '%al' conflicts with asm clobber list

Sorry for so many questions, but I've encountered yet another cryptic error trying to compile the following inline assembly (with -fasm-blocks) which works in MSVC, 开发者_运维知识库but apparently not in GCC and wasn't able to deal with it:

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
    // ...
};

What is this clobber list and what is wrong with it?

I also tried to change optimization level, but it had no effect.


This has to be some bug in gcc (maybe __asm blocks have implicit clobbering). Anyway there are many workarounds:

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

or

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

or

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


the clobber-list is explained here: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html, but not in the context of your __asm syntax, with which I'm not familiar. Trying to compile your snippet I get

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜