test
指令用于两个操作数的按位AND
运算,并根据结果设置标志寄存器,结果本身不会写回到目的操作数。
要点:
1. AND 运算结果为0时, ZF(zero flag)置位;
2. test可以影响CF,OF,PF,SF,ZF标志位;
3. 两个操作数相等,同时为0时,AND 结果为0, 此时ZF置位。
je
指令【Jump if Equals】在ZF被置位时跳转。je
是 jz
【Jump if Zero】的别名。
TEST EAX,EAX
JE some_address
这段代码的含义是:
如果eax==0的话就跳转到”some_address”。
运算过程:
CPU只在 ZF = 1的时候跳转,因此,需要让AND(EAX, EAX) = 0 。而什么时候这个运算为0呢?上文已经提过了,就是EAX = 0的时候。隐含条件是test的两个运算数相等,都为EAX。
等价C代码:
if(eax == 0)
{
goto some_address
}
; Conditional Jump
test cl, cl ; set ZF to 1 if cl == 0
je 0x804f430 ; jump if ZF == 1
; or
test eax, eax ; set SF to 1 if eax < 0 (negative)
js error ; jump if SF == 1
https://stackoverflow.com/questions/13064809/the-point-of-test-eax-eax
https://en.wikipedia.org/wiki/TEST_(x86_instruction)
https://blog.csdn.net/zz709196484/article/details/77755243
https://blog.csdn.net/ms2146/article/details/5279442