views:

88

answers:

3

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!

+1  A: 

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
Mehrdad Afshari
+3  A: 

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
Michael
Thank you! Very helpful and clear!
Ryan
+1  A: 

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.

Michael Burr