Linux的汇编程序错误"在'ASM'&QUOT不可能的约束; [英] Linux assembler error "impossible constraint in ‘asm’"

查看:1988
本文介绍了Linux的汇编程序错误"在'ASM'&QUOT不可能的约束;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始用Linux下的汇编。我有救了以下code作为testasm.c结果
GCC testasm.c -otestasm结果:与它编译
编译器回复:不可能约束的'ASM'。

 的#include<&stdio.h中GT;
INT主要(无效)
{
    INT富= 10,酒吧= 15;    __asm​​__ __volatile__(ADDL %% EBX,EAX %%
    := EAX(富)
    EAX(富),EBX(巴)
    :EAX
    );    的printf(富=%d个富);    返回0;
}

我怎样才能解决这个问题呢?
(我复制了这里 的例子。)

Debian Lenny的,内核2.6.26-2-amd64的结果
gcc版本4.3.2(Debian的4.3.2-1.1)

分辨率:结果
见接受的答案 - 这似乎是修改条款,不支持任何更多


解决方案

  __ asm__ __volatile__(ADDL %% EBX,EAX %%:= A(富):一个(富),b(巴));

似乎工作。我认为,寄存器约束的语法在某种程度上改变了,但它不是非常有据可查的。我觉得它更容易编写原始装配,避免麻烦。

I'm starting with assembler under Linux. I have saved the following code as testasm.c
and compiled it with: gcc testasm.c -otestasm
The compiler replies: "impossible constraint in ‘asm’".

#include <stdio.h>
int main(void)
{
    int foo=10,bar=15;

    __asm__ __volatile__ ("addl %%ebx,%%eax"
    	: "=eax"(foo) 
    	: "eax"(foo), "ebx"(bar) 
    	: "eax" 
    );

    printf("foo = %d", foo);

    return 0;
}

How can I resolve this problem? (I've copied the example from here.)

Debian Lenny, kernel 2.6.26-2-amd64
gcc version 4.3.2 (Debian 4.3.2-1.1)

Resolution:
See the accepted answer - it seems the 'modified' clause is not supported any more.

解决方案

__asm__ __volatile__ ("addl %%ebx,%%eax" : "=a"(foo) : "a"(foo), "b"(bar));

seems to work. I believe that the syntax for register constraints changed at some point, but it's not terribly well documented. I find it easier to write raw assembly and avoid the hassle.

这篇关于Linux的汇编程序错误&QUOT;在'ASM'&QUOT不可能的约束;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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