Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

x86

assembly

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?

like image 522
user997112 Avatar asked Aug 29 '14 20:08

user997112


People also ask

What is the function of Jae in assembly language?

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

What is carry flag in assembly language?

The carry flag (CF) is set when the result of an unsigned arithmetic operation is too large to fit into the destination. • The overflow flag (OF) is set when the result of a signed arithmetic operation is too large or too small to fit into the destination.

What are the flags affected for MOV instruction?

The MOV instruction never affects the flags. Whenever the destination operand equals Zero, the Zero flag is set. A flag is set when it equals 1. A flag is clear when it equals 0.

How do you check the carrying flag?

1. The carry flag is set if the addition of two numbers causes a carry out of the most significant (leftmost) bits added. 2. The carry (borrow) flag is also set if the subtraction of two numbers requires a borrow into the most significant (leftmost) bits subtracted.


2 Answers

jae is the same as jnc, i.e. jump if CF == 0. Choice between all 3 mnemonics (including jnb) is up to programmer. CF isn't set here by mov but by a previous instruction. The mnemonics jae is recommended after compare instruction (cmp) which does subtraction. You can get more details in Intel or AMD software developer manuals.

like image 119
Netch Avatar answered Sep 28 '22 01:09

Netch


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

like image 22
Nowayz Avatar answered Sep 28 '22 02:09

Nowayz