x86 – Difference between JA and JG in assembly
x86 – Difference between JA and JG in assembly
As Intels 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, theyre different. To be precise,
ja
jumps ifCF = 0
andZF = 0
(unsigned Above: no carry and not equal)jg
jumps ifSF = OF
andZF = 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).
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.