简体   繁体   中英

Incomprehensible conditional jump command in assembly

I trying to figure it out, i have these 3 line of assembly code:

cmp     [ebp+var_4], 7
lea     esi, [esi+0]
ja      loc_8048F2C

consider var_4 is -4 and ebp+var_4 is an address of an integer. loc_8048F2C is a label.

Well, I dont understand when the ja (jump if above) command will work. Doesnt the lea command change the flags (like ZF SF etc...) ? I thought each command in assembly change the flags, am I right?

In other words: if my integer is greater than 7, are we jump to loc_8048F2C or not?

No, the LEA instruction doesn't change flags. It is put between CMP and JA so while the processor is busy reading from memory to perform the comparison, it can execute the LEA instruction, that has no dependencies with neither the previous or the following instruction.

Hopefully, when JA instruction is reached, the processor will have the results of CMP ready and no delay will be added.

Not all opcodes modify flags. The lea instruction is one that does not. The flags set by cmp will still have the same value with ja is executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM