I rewrite the code

That code actually does ((Const_A*Const_B) mod 4294967296)/10 (where the "mod" represents the "xor edx, edx").

I think that the correct advice should be clear EDX if you don't know what is it holding or when you know but it is not part of the dividend. And of course don't clear EDX before multiplication because it is unneeded at all :)

`MOV EAX, Const_A`

MOV ECX, Const_B

MUL ECX

XOR EDX, EDX

MOV ECX, 10

DIV ECX

That code actually does ((Const_A*Const_B) mod 4294967296)/10 (where the "mod" represents the "xor edx, edx").

I think that the correct advice should be clear EDX if you don't know what is it holding or when you know but it is not part of the dividend. And of course don't clear EDX before multiplication because it is unneeded at all :)

And of course don't clear EDX before multiplication because it is unneeded at all :)

That is correct. Anything that is in AX, DX:AX or EDX:EAX gets wiped due to the respective values being stored in those registers. Anything out of that order would be considered a severe design flaw :|

As I said before, if you do 16-bit multiplication with the result being in DX:AX, you could clear EDX beforehand if you expect to use EDX in the same manner as you would MOVZX/MOVSX a value. Other various situations apply, but none that require EDX to be cleared for the multiplication logic to work properly.

Well, you can lead a horse to water, but you can't make it drink ;)

**mrgone:**that quote applies to division, not multiplication.

Man, I'm just saying it is a good general rule of thumb. What if you are multiplying a large number that will over flow into EDX and in your result you need the whole integer? You don't want some left over junk in EDX. It could be mistaken as part of the next math operation.

mrgone,

With respect to the 32-bit MUL instruction, the EDX:EAX pair will contain the 64-bit product. No matter what you load into EDX beforehand, it will be overwritten by the MUL instruction. If the product is small, the product can be contained in the EAX register, and the EDX register will set to zero by the MUL instruction. Furthermore the OF and CF flags will be set to zero. If the product is larger than 32-bits, EDX will contain the upper bits (32-63) of the product, and the OF and CF flags will be set. Therefore it is completely unnecessary to clear EDX before a MUL instruction. It will happen as described above no matter what the documentation says or how it is interpreted. Ratch

With respect to the 32-bit MUL instruction, the EDX:EAX pair will contain the 64-bit product. No matter what you load into EDX beforehand, it will be overwritten by the MUL instruction. If the product is small, the product can be contained in the EAX register, and the EDX register will set to zero by the MUL instruction. Furthermore the OF and CF flags will be set to zero. If the product is larger than 32-bits, EDX will contain the upper bits (32-63) of the product, and the OF and CF flags will be set. Therefore it is completely unnecessary to clear EDX before a MUL instruction. It will happen as described above no matter what the documentation says or how it is interpreted. Ratch