Reputation: 3605
I am having trouble understanding the difference between ja and jg for assembly language. I have a section of code:
cmp dh, dl
j-- hit
and am asked which conditional jump to hit (that replaces j-- hit) will be taken with the hex value of DX = 0680.
This would make dl = 06 and dh = 80, so when comparing, 80 > 06. I know that jg fits this as we can directly compare results, but how should I approach solving if ja fits (or in this case, does not fit) this code?
Upvotes: 2
Views: 15965
Reputation: 223073
dx
is 0x0680, then dh
is 0x06 and dl
is 0x80.jg
, since 6 > -128, but 6 < 128. jg
does signed comparison; ja
does unsigned comparison.Upvotes: 10
Reputation: 26271
The difference between ja
and jg
is the fact that comparison is unsigned for ja
and signed for jg
(treating the registers as signed vs unsigned integers).
If the numbers are guaranteed to be positive (i.e. the sign bit is 0) then you should be fine. Otherwise you have to be careful.
You really can't intuit based on the comparison instruction itself if ja
is applicable. You have to look at the context and decide if sign will be an issue.
Upvotes: 9