user997112
user997112

Reputation: 30615

How is the x86 JAE instruction related to the carry flag?

I have some x86 code which looks like:

;  The carry flag is set to 1 here
jae    an_address  ; The jump instruction does not take place

Does this make sense?

I thought the jump should take place because 1 is greater than or equal to 0, the definition of JAE?

Upvotes: 8

Views: 20246

Answers (2)

Netch
Netch

Reputation: 4572

jae (jump if above or equal) is the same as jnb (jump if not below) and jnc (jump if not carry), i.e. jump if CF == 0. The choice between all 3 mnemonics is up to the programmer. The CF isn't set here by mov but by a previous instruction.

The mnemonics jae and its logical synonym jnb are recommended after a compare instruction (cmp) which does subtraction, as opposed to jnc for cases where the CF is affected by bit operations (shifts, single-bit manipulations like btc, etc.). It's the same machine code, but a different way to think about the meaning for human readers, in terms of a comparison result vs. in terms of the actual flag value itself.

You can get more details in Intel or AMD software developer manuals, or an HTML extract of just Intel's vol.2 entry for jcc

Upvotes: 16

Nowayz
Nowayz

Reputation: 1948

jae means Jump if above or equal. It will jump if the carry flag is equal to 0.

You're looking for jnae or jb

Upvotes: 7

Related Questions