문제

I'm trying to convert an inline asm code form VS to GCC (AT&T).. the original code is this one:

char mystr[] = "Hello world";
_asm mov eax,0
_asm lea ebx, [mystr]

Here is my attempt to convert that code in gcc at&t syntax:

char mystr[] = "Hello world";
asm("mov $0,%%eax\n"
    "leal (%0),%%ebx\n"
    : : "r"(mystr));

This code doesn't seems to work, any idea why ? Thank you very much

도움이 되었습니까?

해결책

This code seems to works:

char* mystr = "Hello world";

asm("mov $0,%%eax\n"
    "leal (%0),%%ebx"
    ::"b"(mystr));

I've changed char mystr[] to char* mystr, and "r" with "b".. If somebody know what "b" does exactly, please let me know... many thanks

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top