IDIV operation in assembly (understanding)

孤者浪人 提交于 2020-12-26 07:39:47

问题


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 know that the quotient is stored in eax and the remainder in edx.

so but what exactly is the value in edx:eax ??

Can someone explain it to me?

edit: i also did not understand the reason of "cdq" operation which come always before the IDIV operation although I have read some pages about that.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/25489192/idiv-operation-in-assembly-understanding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!