/*
* An example of using jumps in inline assembly
*
* 处理跳转
*/
#include <stdio.h>
int main()
{
int a = 10;
int b = 20;
int result;
asm("cmp %1, %2\n\t"
"jge greater\n\t"
"movl %1, %0\n\t"
"greater:\n\t"
"movl %2, %0\n\t"
"end:\n\t"
: "=r"(result)
: "r"(a), "r"(b));
printf("The larger value is %d\n", result);
return 0;
}
// 进一步改写
int main()
{
int a = 10;
int b = 20;
int result;
asm("cmp %1, %2\n\t"
"jge 0f\n\t"
"movl %1, %0\n\t"
"jmp 1f\n\t"
"0:\n\t"
"movl %2, %0\n\t"
"1:\n\t"
: "=r"(result)
: "r"(a), "r"(b));
printf("The larger value is %d\n", result);
return 0;
}