Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top