assemblyconditional-statementsx86att

Unsure about cmp/jg behavior in AT&T syntax


I have some assembly code that is not behaving as expected, specifically these lines:

cmp $0x5, %eax
jg 

I am stepping through gdb, and putting a breakpoint on the line with cmp. At that point in time, eax holds the value 0x1

Thus, 0x5 is greater than 0x1, so it should be taking the jump. However the code does not take the jump.

Am I missing something easy here?


Solution

  • I think your confusion is caused by that &#^?%*$! AT&T syntax :)

    In Intel's own syntax it would be

    cmp eax, 5
    jg
    

    which (IMHO) makes it much more obvious that the jump is taken if the value of eax is greater than 5.