Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 733
Benjoyo Avatar asked Apr 12 '26 04:04

Benjoyo


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!