简体   繁体   中英

What gets compared to what in the cmovl opcode?

In the assembly opcode cmovl, what gets compared? For example: EAX: 00000002 EBX: 00000001

cmovl eax,ebx

What is the result? Which one needs to be less so they can be moved?

Thank you!

cmov doesn't do a comparison, it uses the result of a previous comparison - if it is true, it will perform the mov. cmovl means "perform move if previous comparison resulted in "less than".

For example:

cmp ecx, 5
cmovl eax, ebx ; eax = ebx if ecx < 5

It should be preceded by another instruction that sets flags appropriately, like cmp .

cmp ebx, ecx   ; compare ebx to ecx and set flags.
cmovl ebx, eax ; if (ebx < ecx (comparison based on flags)) ebx = eax 

cmovl will perform the move if the flags register has the following: SF!=OF

Those flags would be set as the result of some previous operation (typically, but not necessarily, a compare of some sort).

The cmovl instruction does not perform a compare of its own.

In AT&T assembly the equivalent code would be:

cmp   %ebx, %eax
cmovl %ebx, %eax

which would copy the value of %ebx to %eax , if the value held in %eax was greater than the value held in %ebx at the time of the cmp call.

With your example values, the result would be that the conditional move would not copy the value from %ebx to %eax , as 0x02 is clearly greater than 0x01 .

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