cmp是比较指令,cmp的功能相当于减法指令(sub)。它不保存结果,只是影响相应的标志位。其他的指令通过识别这些被影响的标志位来得知比较结果。
cmp指令格式: cmp 操作对象1, 操作对象2
cmp指令格式: cmp 操作对象1, 操作对象2
注意是计算 操作对象2 - 操作对象1,和sub的一样,而不是 操作数1-操作数2(ATT格式), 但不保存结果,只是根据结果修改相应的标志位。
附我自己写的测试用汇编:
#include
<stdio.h>
int main()
{
int eax = 100;
int ebx = 200;
int output = -100;
asm volatile(
"movl %1,%%eax;\n\t"
"movl %2,%%ebx;\n\t"
"cmpl %%eax,%%ebx;\n\t" //用的是cmpl比较指令
"sets %%al;\n\t"
//负数时设置
"movzbl %%al,%%eax;\n\t"
"movl %%eax,%0\n\t"
: "=m"(output)
: "r"(eax), "r"(ebx)
: "eax");
printf("%d \n", output);
return 0;
}
最终的输出是1