X86 cmpl and jne

assemblyattx86

I'm tracing some x86 code for an assignment, and I was wondering what exactly "cmpl" does and how to predict whether or not the "jne" will be met.

80484bf:    83 7d f0 07             cmpl   $0x7,-0x10(%ebp)
80484c3:    75 16                   jne    80484db

Best Answer

cmpl subtracts -0x10(%ebp) from $0x7 and modifies flags: AF CF OF PF SF ZF.

  1. If memory at -0x10(%ebp) equals immediate 0x7 then the flag ZF is set. This is below EBP so it's probably a local variable, if this is an un-optimized build using EBP as a frame pointer.
  2. jne 80484db means that if the two compared numbers are different (ZF=0), jump to 80484db

To summarize, your code is equivalent to :

compare A to 7
jump to 0x80484db if they are different.