If two mnemonics assemble to the same opcode, by definition the machine will run them the same way. The CPU can only see the machine code, not the asm source. (You won't see <
in the asm docs because that only applies if FLAGS were set by cmp
or sub
.)
And yes, https://www.felixcloutier.com/x86/jcc scraped from Intel's official PDFs (https://software.intel.com/content/www/us/en/develop/articles/intel-sdm.html) confirms that JL
is "Jump short if less (SF≠ OF)."
Probably somewhere in Intel's Vol.1 they explain how cmp
+ JCC makes mnemonics match the "semantic meaning" they're named for. See also Assembly - JG/JNLE/JL/JNGE after CMP
As for the FLAGS setting, cmp x, y
is like x - y
just setting FLAGS. The result will be negative (SF set) if y is a larger number, unless you have signed overflow. See http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt for details on how OF is set by subtraction.
Note that subtraction of two equal-width numbers can only overflow once, not overflow and wrap all the way around back to negative (or the same sign as the correct result).
- if SF=1 and there was no overflow,
x-y < 0
so x < y
.
- if SF=0 and there was no overflow,
x-y >= 0
so it's not true that x < y
- If there was overflow, SF is opposite of the sign-bit of the correct result. (That's exactly what signed overflow is, see the linked guide).
SF != OF
is the XOR of those two bits: flip SF to find the sign of the correct result and consult the appropriate one of the no-overflow cases.
So we can prove that SF != OF
is the right condition for cmp eax, edx
/ jl
to be taken iff eax < edx
(signed). Combined with the official documentation that describes their operation as jump if SF != OF
, yes, we've proved that JL
(and JNGE
) match their mnemonics. If you want to flesh that out into a more rigorous proof with definitions of exactly what OF
means, you can.
If you run jl
after a different instruction, like add eax, edx
, it will still check those flags, but the way they're set won't have anything to do with one being less than the other. That's why <
isn't an inherent part of jl
itself, just of what happens if you use it after cmp
. (Or after test eax,eax
, which sets FLAGS identically to cmp eax, 0
, i.e. an implicit compare against zero, like for any operation that always clears OF, and sets SF and ZF according to the result.)