两个C/C++与汇编进行混合编程的小例子

//第一个例子:汇编语句实现子函数 #include short addasm(short a,short b,short c) { short sum; __asm { mov ax,a; add ax,b; add ax,c; mov sum,ax; } return sum; } void main() { short a,b,c,sum; a = 10; b = 20; c = 30; sum = addasm(a,b,c); printf("sum = %d /n",sum); } //第二个例子:汇编语句直接嵌入主函数 #include void main() { int a,b,c,sum; a = 10; b = 20; c = 309; __asm { mov eax,a; add eax,b; add eax,c; mov sum,eax; } printf("sum = %d /n",sum); }

你可能感兴趣的:(底层研究)