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
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
.