Assembly Language: difference between ja and jg?

15,586

Solution 1

  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.

Solution 2

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.

Share:
15,586
raphnguyen
Author by

raphnguyen

Updated on June 17, 2022

Comments

  • raphnguyen
    raphnguyen almost 2 years

    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?