Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174337
  • 博文数量: 69
  • 博客积分: 2627
  • 博客等级: 少校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-24 22:37
文章分类

全部博文(69)

文章存档

2017年(3)

2014年(1)

2013年(4)

2012年(6)

2011年(21)

2010年(15)

2009年(19)

我的朋友

分类: LINUX

2011-08-07 23:30:10

测试下%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
阅读(468) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~