Benjoyo
Benjoyo

Reputation: 423

gcc inline - operand type mismatch for 'cmp'

I get the following error:

Assembler messages:
Error: operand type mismatch for `cmp'

The only cmp in my code is:

"cmpl %eax, $15\n\t"

I don't get what is wrong with that - I have a register and an immediate value which should be implicitly sign extended to 32bit.

Upvotes: 3

Views: 5503

Answers (2)

user8243991
user8243991

Reputation:

According to Official Intel ISA Reference 3.2 Instructions (A-L)

CMP EAX, imm32

Which means either in Intel Syntax

cmp eax, 15D

or in AT&T Syntax:

cmpl $15, %eax

Just the opposite :)


cmp doesn't have a form that subtracts the reg/mem from an immediate. Instead, use the opposite branch / cmov condition if you wanted to check something other than equality.

Upvotes: 1

Tosan79
Tosan79

Reputation: 1

i had the same problem, but in my case the error was with

cmp $0xFFFFFFFFFFFFFFFF, %rdx

and the solution was to do

movq $0xFFFFFFFFFFFFFFFF, %rcx

first, and then

cmp %rcx, %rdx

(afaik, for bigger numbers cmp needs two registers, not const and register)

Upvotes: 0

Related Questions