IDIV operation in assembly (understanding)

后端 未结 2 904
后悔当初
后悔当初 2021-01-21 09:30

when I have the the operation

IDIV ecx

in assembly, then i have read that the that the value in edx:eax is divided by the operand ecx. I also

相关标签:
2条回答
  • 2021-01-21 09:52

    i have read that the that the value in edx:eax is divided by the operand ... but what exactly is the value in edx:eax ?

    EDX:EAX in this context means the 64-bit value formed by the registers EDX and EAX, where EDX is interpreted as containing the most significant bits, and EAX the least significant bits.

    CDQ converts the doubleword in EAX into a quadword in EDX:EAX by sign-extending EAX into EDX (i.e. each bit of EDX is filled with the most significant bit of EAX). For example, if EAX contained 0x7FFFFFFF you'd get 0 in EDX, since the most significant bit of EAX is clear. But if you had EAX = 0x80000000 you'd get EDX = 0xFFFFFFFF since the most significant bit of EAX is set.
    The point of CDQ is to set up EDX prior to a division by a 32-bit operand, since the dividend is EDX:EAX.

    0 讨论(0)
  • 2021-01-21 10:06

    What is it? It's the value you put there because you want to divide it...

    The CDQ instruction takes a 32-bit value in EAX and converts it into a 64-bit value in EDX:EAX (by copying the sign bit of EAX into every bit of EDX). You use it if (as is usual) the value you want to divide is 32-bit to begin with.

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