开发者

Assembly Language: difference between ja and jg?

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 j开发者_如何学Pythona fits (or in this case, does not fit) this code?


  1. If dx is 0x0680, then dh is 0x06 and dl is 0x80.
  2. 0x80 is interpreted as 128 in unsigned mode, and -128 in signed mode.
  3. Thus, you have to use jg, since 6 > -128, but 6 < 128. jg does signed comparison; ja does unsigned comparison.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜