cassemblygccx86inline-assembly

Problem with assembly statements in gcc


I encountered a piece of assembly code in a C program I was trying to run in FreeBSD 64-bit.

void  *curbrk;   
__asm__ __volatile__(
        "movl .curbrk, %%eax;"
        "movl %%eax, %0"
            : "=r" (curbrk)
            :: "%eax"
    );

I get an error like "mov missing suffix or operand".(The above code follows AT&T syntax) What determines the syntax i should use for the code - The compiler (gcc follows AT&T syntax) or the processor (I'm working on an Intel Processor). Is the problem due to the fact that the code is in AT&T syntax or is there anything else I'm missing?


Solution

  • If you have a 64-bit GCC, the above code will not complete unless you use the -m32 switch to output 32-bit object code, because the 64-bit pointer value will not fit into the 32-bit EAX register. Either use -m32 to generate 32-bit output, or use rax inplace of eax and change the movl's to mov (without 'l')