Wednesday, October 08, 2008

簡單的Gas inline assembly

簡單的gas入門嘗試如下,output field裡頭的"=r"改成"+r"之後就一帆風順了。
=是write only的意思。+是read-write。

#include

void main()
{
int x = 1;
int z = 3;
int y = 0;
printf("x = %d,y = %d, z = %d",x, y, z );

__asm__ __volatile__("movl %1, %0\n\t"
"movl %2, %0\n\t"
:"+r"(y)
:"r"(z),"r"(x)
:"0"
);

printf("\nx = %d, y = %d, z = %d", x, y, z);

}

No comments: