This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Inline Assembly, MOV, and Memory Operand Constraint
On 15/06/11 08:25, Jeffrey Walton wrote:
> Hi All,
>
> I have a question on inline assembly. For my first experiment, I'm
> trying to read the flags register. Intuitively, I'm trying to perform
> the following:
> mov %eax, result
>
> The assembler does not take the simple syntax (see [1], [2]), andI'm
> having trouble getting the statement right. I've tried lots of
> variations on the following, but have yet to find success.
> unsigned int result;
> ...
> asm volatile("mov %eax, result" : "=m(result)");
Should be
unsigned int result;
void ping() {
asm volatile("mov %%eax, %0" : "=m"(result));
}
.comm result,4,4
.text
.globl ping
.type ping, @function
ping:
pushl %ebp
movl %esp, %ebp
#APP
# 4 "t.c" 1
mov %eax, result
# 0 "" 2
#NO_APP
popl %ebp
ret
Andrew.