Assembly x86 registers signed or unsigned

前端 未结 2 1078
灰色年华
灰色年华 2020-12-20 19:47

I know this is a really simple question, but I couldn\'t find an answer to this. Are the registers in x86 assembly (eax, ebx edx etc) signed or unsigned? If they\'re signed

相关标签:
2条回答
  • 2020-12-20 20:04

    The CPU does not know nor does it care. Instead, bits in the Flags register are set on certain operations, and how your program acts on those flags depends on what the source code told it to.

    E.g.,

    mov eax, 0FFFFFFFFh
    test eax, eax
    js isNegative
    

    vs.

    mov eax, 0FFFFFFFFh
    test eax, eax
    jb isNegative
    

    The first jumps to 'IsNegative' because test sets the Sign Flag here. The second does not, because test resets the Carry Flag to 0 and jb only jumps if it is 1.

    0 讨论(0)
  • 2020-12-20 20:19

    32-bit registers in x86 are default unsigned. For example, a move from 32-bit operand to a 64-bit register always get zero-extended under long model. But instructions each has its own interpretation of registers based on its purpose, like 'add' instruction take registers both signed or unsigned. You should refer intel documents for detail.

    0 讨论(0)
提交回复
热议问题