linu-汇编-条件分支和非条件分支、内联宏函数(5)

 

1、在jmp,jge等跳转语句的跳转标签处加上f和b,f为向前,b为向后。

2、用数字0、1等表示中转的标签

.....

....

asm(

"cmp %1,%2\n\t"

"jge 0f\n\t"

"addl %1,%2\n\t"

"jmp 1f\n\t"

"0:\n\t"

"addl %1,%2\n\t"

"1:\n\t"

)

3、使用define定义内联宏函数

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

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

8

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


#include <stdio.h>
#define addnums(a,b,result) ({\
asm(\
"addl %1,%2\n\t"\
"movl %2,%0\n\t"\
:"=r"(result)\
:"r"(a),"r"(b));})


int main(int argc,char *argv[]){
  int x,y,res;
  x=2;y=6;
  addnums(x,y,res);
  printf("%d\n",res);
  return (0);
}
 

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