1

What is a (working) example of Conditional mov (cmov) example? Inline asm in C preferred. I am not sure if it needs cmp before it or not. Also, I tried to make the below with CMov, but can't do it.

int n = 0, d;
int a[5];
a[0] = 134;
a[1] = 70;
a[2] = 735;
...
__asm
{
LEA edi, a
mov eax, 150
//cmp eax, 128 ; if legal & needed
cmovae eax,[EDI+1]
mov d, eax
}

Either VC or GCC are welcomed! Please explain about cmov more.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
user683595
  • 397
  • 1
  • 3
  • 10
  • 5
    An optimizing compiler (e.g. a recent `gcc-4.7` with `-O2` or `-O3` flags) is able to emit such `cmov` instructions by itself and without any explicit `asm` from your part. – Basile Starynkevitch Nov 22 '12 at 14:35
  • 2
    All that's really needed for a `cmov` to work is that the condition flags be set, eg. by a `cmp`, `test` or similar – Hasturkun Nov 22 '12 at 14:39
  • That should be simple, `cmov??` uses the same condition codes as conditional jumps `j??`. For example, `test eax, eax; cmovz ebx, edx` will replace `ebx` if replacing `cmovz` with `jz` would jump. @BasileStarynkevitch: MSVC 2010 doesn't seem to emit `cmov` on its own, don't know about 2012. – DCoder Nov 22 '12 at 14:41
  • thank you, yes, it needs CMP, it is now workin' :) – user683595 Nov 22 '12 at 14:48

0 Answers0