[英]Combination of AND and JGE in assembly
I have the following assembly lines which I do not understand exactly: 我有以下我不完全了解的装配线:
...
AND EDX, 0x80000003
JGE SHORT prog.00401304
...
Normally I have always seen the JGE
instruction after CMP
instruction. 通常,我总是在
CMP
指令之后看到JGE
指令。 With a CMP
I must look if the first operand is greater or equal than the second operand. 对于
CMP
我必须查看第一个操作数是否大于或等于第二个操作数。 But with and AND
, I do not know. 但是,使用
AND
,我不知道。 Can somebody tell me how I must interpret it with and AND
instruction? 有人可以告诉我如何使用
AND
指令解释它吗? Should I perform the AND
operation on EDX
with the value 0x80000003? 我应该在
EDX
上执行AND
运算,值为0x80000003吗? And then? 接着? How it can look in a pseudo-C code language?
伪C代码语言的外观如何?
and
modifies flags
in the following way (See Intel® 64 and IA-32 Architectures Software Developer's Manual Combined Volumes:1, 2A, 2B, 2C, 3A, 3B and 3C): and
以以下方式修改flags
(请参阅《英特尔®64和IA-32体系结构软件开发人员手册》合卷:1、2A,2B,2C,3A,3B和3C):
Flags Affected
The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to
the result. The state of the AF flag is undefined.
jge
means "Jump if greater or equal (SF=OF)", it's synonymous with jnl
. jge
意思是“如果大于或等于(SF = OF),则跳转”,它与jnl
同义。 See Intel x86 JUMP quick reference . 请参阅Intel x86 JUMP快速参考 。
As OF
(overflow flag) is always cleared (set to zero) after and
, and jge
jumps when (SF=OF), jge
after and
jumps when SF
is set to zero, that is, when the highest bit of the result (here edx
is set to zero), which means that the signed result is zero or positive integer (0..2147483647). 如
OF
(溢出标志)始终清零(设置为零)之后and
,和jge
跳跃时(SF = OF), jge
之后and
当跳跃SF
被设置为零,即,当结果的最高位(这里edx
设置为零),这意味着有符号结果为零或正整数(0..2147483647)。
You should have consulted the instruction set reference. 您应该已经查阅了指令集参考。
JGE
operates based on flag bits, namely: Jump if greater or equal (SF=OF)
. JGE
基于标志位进行操作,即: Jump if greater or equal (SF=OF)
。 Okay, now you need to figure out the value of those flags. 好的,现在您需要弄清楚这些标志的值。 You turn to the page describing the operation of the
AND
instruction and see: The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result
您转到描述
AND
指令的操作的页面AND
然后看到: The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result
The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result
. The OF and CF flags are cleared; the SF, ZF, and PF flags are set according to the result
。 0x80000003
has the highest bit set, thus after the AND
operation SF
gets the highest bit of EDX
(also known as the sign bit). 0x80000003
设置了最高位,因此在“ AND
运算之后AND
SF
获得了EDX
的最高位(也称为符号位)。 All in all, the branch is taken if the EDX >= 0
, because then SF
= OF
= 0
. 总而言之,如果
EDX >= 0
,则采用分支,因为SF
= OF
= 0
。
NRZ explained that OK. NRZ解释说可以。 I will add that JGE in that code is equivalent to JNS.
我将在该代码中添加JGE等效于JNS。 A small piece of C-code that produces these assembly instructions is:
产生这些汇编指令的一小段C代码是:
test( ) {
int i;
i &= 0x80000003;
if( i < 0 ) i = -i;
}
If you compile it with 如果用
cl /c /FAs test.c
the listing (part of it ) is : 列表(部分)是:
; 2 : int i;
; 3 : i &= 0x80000003;
mov eax, DWORD PTR _i$[ebp]
and eax, -2147483645 ; 80000003H
mov DWORD PTR _i$[ebp], eax
; 4 : if( i < 0 ) i = -i;
jge SHORT $LN2@test
mov ecx, DWORD PTR _i$[ebp]
neg ecx
mov DWORD PTR _i$[ebp], ecx
$LN2@test:
Keep in mind that the MOV instruction after AND does not affect flags. 请记住,AND之后的MOV指令不会影响标志。
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.