0

Can you please tell me the difference between ja (jump if above) and jnbe (jump if not below or equal) instructions in x86 assembly? When do I use each of them? do they give me different results?

mediocrevegetable1
  • 4,086
  • 1
  • 11
  • 33
TryHard
  • 11
  • 3

1 Answers1

5

Assuming you mean the ja and jnbe mnemonics in x86 assembly: There's no difference; they are two different mnemonics for the exact same instruction. You can consult the official instruction description and see that they correspond to the exact same machine code (77 cb for an 8-bit "short" offset, 0f 87 cw/cd for a 16- or 32-bit "near" offset).

So it makes no difference to the machine, only to the human programmers who read and maintain your code. It gives you the freedom to write whichever one seems more intuitive for what your code is doing.

Many of the other x86 conditional instructions have multiple mnemonics for similar situations. For example jb, "jump if below", jumps precisely when the carry flag is set, making it the same instruction as jc, "jump if carry". But having two mnemonics means you can write things like:

add eax, ebx
jc there_was_a_carry
...
cmp ecx, edx
jb ecx_is_smaller

Combinations like add / jb and cmp / jc would be equivalent to the machine, but less clear for the programmer.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • Yup, different mnemonics for the same opcode let you pick the one that has the desired **semantic meaning** for human readers of your asm source. (The distinction is lost if you're disassembling machine-code; then you have to remember the equivalence.) Pretty sure this question has come up before, maybe for a different pair like JE / JZ; probably should get closed as a duplicate in one direction or the other. – Peter Cordes Apr 18 '21 at 22:56