The difference between cmpl and cmp

前端 未结 3 1612
星月不相逢
星月不相逢 2021-02-07 17:50

I am trying to understand assembly to be able to solve a puzzle. However I encountered the following instructions:

0x0000000000401136 <+44>:    cmpl   $0x7,         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 18:33

    According to my understanding cmpl compares unsigned.

    It does both, in a way.

    The difference in signed vs. unsigned is here the usage of the jump instructions.

    For >, there is ja for unsigned and jg for signed (jump if above and jump if greater).

    For <, there is jb for unsigned and jl for signed (jump if below and jump if less).

    To be exact, here is the meaning of several jump commands:

    For unsigned comparisons:

    JB/JNAE (CF = 1)           : Jump if below/not above or equal
    JAE/JNB (CF = 0)           : Jump if above or equal/not below
    JBE/JNA (CF = 1 or ZF = 1) : Jump if below or equal/not above
    JA/JNBE (CF = 0 and ZF = 0): Jump if above/not below or equal
    

    For signed comparisons:

    JL/JNGE (SF <> OF)          : Jump if less/not greater or equal
    JGE/JNL (SF = OF)           : Jump if greater or equal/not less
    JLE/JNG (ZF = 1 or SF <> OF): Jump if less or equal/not greater
    JG/JNLE (ZF = 0 and SF = OF): Jump if greater/not less or equal
    

提交回复
热议问题