linux-汇编-内联汇编(1)

deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o testasmc testasmc.c

deepfuture@deepfuture-laptop:~/private/mytest$ ./testasmc

12

30

deepfuture@deepfuture-laptop:~/private/mytest$ 


#include <stdio.h>
int c=10;
int d=20;
int addresult;
int main(void){
    int a=6;
    int b=2;
    int result;
    result=a*b;
    asm("nop\n\t"
    "nop\n\t"
    "nop\n\t"
    "nop");//4个nop指令,\n\t表示换行,然后加上TAB行首空,因为每个汇编指令必须在单独一行,需要换行,加上制表符是为了适应某些编译器的要求。    
    printf("%d\n",result);
    asm("pusha\n\t"
    "movl c,%eax\n\t"
    "movl d,%ebx\n\t"
    "add %ebx,%eax\n\t"
    "movl %eax, addresult\n\t"
    "popa");//使用全局C变量c和d    
    printf("%d\n",addresult);    
    return 0;
}

你可能感兴趣的:(C++,c,linux,gcc,C#)