|
发表于 2006-1-24 11:30:54
|
显示全部楼层
摘录于Linux1.0核心游记之内嵌汇编示例
文件名swap.c
#include <stdio.h>
int
main()
{
int iValue = 100;
int jValue = 200;
printf("\nBefore Swap:a=%d,b=%d\n",iValue,jValue);
__asm__
("movl (%0),%%eax\n\t"
"movl (%1),%%edx\n\t"
"movl %%eax,(%1)\n\t"
"movl %%edx,(%0)\n\t"
::"b"(&iValue),"c"(&jValue)
);
printf("After Swap:a=%d,b=%d\n\n",iValue,jValue);
return 0;
}
文件名Makefile
GCC=gcc
OBJS=swap
.c.o:
$(GCC) -c -Wall $<
all(OBJS)
$(OBJS):swap.o
$(GCC) -o $(OBJS) swap.o
clean:
rm -f *.o core
clobber:clean
rm -f $(OBJS)
|
|