Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between JA and JG in assembly

Can you please tell me the difference between JUMP IF ABOVE AND JUMP IF GREATER in Assembly language? when do i use each of them? do they give me different results?

like image 545
user3157687 Avatar asked Jan 03 '14 15:01

user3157687


People also ask

What does JA do?

Purpose. Junior Achievement's purpose is to inspire and prepare young people to succeed in a global economy.

What is the difference between the JA and JNBE instructions?

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.


2 Answers

As Intel's manual explains, JG interprets the flags as though the comparison was signed, and JA interprets the flags as though the comparison was unsigned (of course if the operation that set the flags was not a comparison or subtraction, that may not make sense). So yes, they're different. To be precise,

  • ja jumps if CF = 0 and ZF = 0 (unsigned Above: no carry and not equal)
  • jg jumps if SF = OF and ZF = 0 (signed Greater, excluding equal)

For example,

cmp eax, edx ja somewhere ; will go "somewhere" if eax >u edx              ; where >u is "unsigned greater than"  cmp eax, edx jg somewhere ; will go "somewhere" if eax >s edx              ; where >s is "signed greater than" 

>u and >s agree for values with the top bit zero, but values with the top bit set are treated as negative by >s and as big by >u (of course if both operands have the top bit set, >u and >s agree again).

like image 80
harold Avatar answered Oct 06 '22 03:10

harold


JA is used for jumping if the last "flag changing" instruction was on unsigned numbers. but on the other hand, JG is used for jumping if the last "flag changing" instruction was on signed numbers.

like image 23
Rahimi0151 Avatar answered Oct 06 '22 03:10

Rahimi0151