Condition: jumps if SF ≠ OF. After CMP a, b you might expect the sign of a − b alone to answer "is a less than b?", but the subtraction can overflow, and then the sign bit lies. OF records exactly that case, so the CPU compares the two: when they differ, the true difference is negative and a < b.
| After CMP a, b | Unsigned | Signed |
|---|---|---|
| a = b | JE (ZF = 1) | JE (ZF = 1) |
| a ≠ b | JNE (ZF = 0) | JNE (ZF = 0) |
| a > b | JA (CF = 0 and ZF = 0) | JG (ZF = 0 and SF = OF) |
| a ≥ b | JAE (CF = 0) | JGE (SF = OF) |
| a < b | JB (CF = 1) | JL (SF ≠ OF) |
| a ≤ b | JBE (CF = 1 or ZF = 1) | JLE (ZF = 1 or SF ≠ OF) |
The example is chosen so that SF alone gives the wrong answer: −100 − 100 = −200 does not fit in a byte, the stored result is 56 (SF = 0), and OF = 1.
MOV AL, -100CMP AL, 100 ; -200 overflows: SF = 0, OF = 1MOV DL, "Y" ; MOV leaves the flags aloneJL SHOW1 ; taken: DL stays "Y"MOV DL, "N"SHOW1:MOV AH, 02h ; DOS: print the character in DLINT 21h
Range
On the 8086 JL exists only in the SHORT form: two bytes, opcode 7Ch and a signed 8-bit displacement counted from the end of the instruction. The target must lie within −128..+127 bytes of that point. To go farther, invert the test and hop over an unconditional JMP, which can reach the whole segment. MASM 6 makes this rewrite itself when it finds the target out of range (its default OPTION LJMP), so the listing may show two instructions where you wrote one.
JGE SKIP1 ; the opposite test, a short hopJMP FARAWAY ; any distance in the segmentSKIP1:
Later CPUs
The 80386 added a near form of every conditional jump, 0Fh 8Ch followed by a 16-bit displacement (32-bit in 32-bit code), so from the 386 on JL can reach anywhere in the segment. Code for the 8086 must stay with the short form.