Regarding cmp / jg, jle, etc in AT&T syntax assembly

前端 未结 2 398
说谎
说谎 2021-01-22 16:23

So every single resource online tells me that something like this:

cmp %eax, %ebx
jg < something >

would jump to < something > if eax

2条回答
  •  深忆病人
    2021-01-22 16:50

    When we read something like

    cmp $0x2, %eax
    jg  < something >
    

    we know the assembler used is one that reverses the position of the operands of an instruction. That's because Intel's syntax dictates that the destination operand comes before the source operand and clearly an immediate value like $0x2 can't ever be a destination!

    Knowing the order of things we now interpret your first code snippet as

    cmp ebx, eax
    jg < something >  ;jump if EBX > EAX
    

    and the second code snippet as

    cmp eax, 2
    jg < something >  ;jump if EAX > 2
    

    And does this apply to other jump statements as well?

    It does.

提交回复
热议问题