测试下%0,%1,...,0,1,...,"m"分别指代哪些东西
#include
void print_msg1(){
printf("some str1.\n");
}
void print_msg2(){
printf("some str2.\n");
}
void main(){
int iv1=10,iv2=30,result=0,nouse;
int *p;
//不使用占位符%0,%1,...
__asm__ (
"addl %%ebx,%%eax \n\t"
: "=a"(result)
: "b"(iv1),"a"(iv2)
);
printf("result1=%d\n",result);
//使用占位符%0,%1,... %1=ebx, %2=eax
iv1+=2;
__asm__ (
"addl %1,%2 \n\t"
: "=a"(result)
: "b"(iv1),"a"(iv2)
);
printf("result2=%d\n",result);
//使用占位符%0,%1,...
iv1+=2;
__asm__ (
"addl %2,%3 \n\t" // %2=ebx, %3=eax
: "=a"(result),"=b"(nouse)
: "1"(iv1),"0"(iv2) // 0 指 eax 1 指 ebx
);
printf("result3=%d,nouse=%d\n",result,nouse);
//没有输出的情况下%1指哪个:在没有输出的情况下,%0,指输入的第一个寄存器,%1指第二个寄存器
iv1+=2;
__asm__ (
"cmpl $16,%0 \n\t"
"je 1f\n\t"
"cmpl $30,%0 \n\t"
"je 2f\n\t"
"1: call _print_msg1\n\t"
"jmp 3f\n\t"
"2: call _print_msg2\n\t"
"3:\n\t"
:
: "b"(iv1),"a"(iv2)
);
//测试下"m"
__asm__ (
"addl %1,%2 \n\t" //%2指eax
: "=a"(result)
: "m"(iv1),"a"(iv2)
);
printf("result4=%d\n",result);
//测试下"m"
p=&iv1;
__asm__ (
"addl %1,%2 \n\t" //%2指eax
: "=a"(result)
: "m"(*p),"a"(iv2)
);
printf("result5=%d\n",result);
}
在windows平台下使用djgpp编译,运行结果:
result1=40
result2=42
result3=44,nouse=14
some str1.
result4=46
result5=46
阅读(477) | 评论(0) | 转发(0) |