Akiiino
Akiiino

Reputation: 1100

Operand type mismatch for cmov

I can't seem to get cmove to work the way I want it to. I have this bit of code:

cmove   $1, %eax

And I get this error on compilation:

Error: operand type mismatch for `cmove'

However, replacing cmove with, say, mov works perfectly, and

mov    $1,   %ecx
cmove  %ecx, %eax

works too. I've tried to use cmovel as well, but it just doesn't work. Am I missing something?

Upvotes: 5

Views: 2526

Answers (1)

Michael
Michael

Reputation: 58467

Am I missing something?

For cmove $1,%eax to work there'd have to be a form of cmove that accepts r32,imm (or r/m32,imm) as an argument combination. But the only valid forms of cmove listed in Intel's manual are:

CMOVE r16, r/m16
CMOVE r32, r/m32
CMOVE r64, r/m64

In the description for CMOVcc they spell this out:

These instructions can move 16-bit, 32-bit or 64-bit values from memory to a general-purpose register or from one general-purpose register to another.

Upvotes: 6

Related Questions