0

i have the following assembly lines:

...
MOV ECX, 0x36EE80
MOV EDX, 0x95217CB1
MUL EDX
SHR EDX, 0x15
MOV DWORD PTR SS:[EBP-0x3C8], EDX
....
....

So, in http://en.wikibooks.org/wiki/X86_Assembly/Arithmetic I have read that the value of the operand of MUL (in that case EDX) is multiplied with the value in EAX. So, in EAX I have the value 0330FD3B (decimal: 53542203). In EDX, i have the value 95217CB1 (in decimal: 2501999793). But after the MUL operation i have in EDX the value 01DBEE41(in decimal: 31190593). But this must be wrong because 53542203 * 2501999793 is not 31190593...

Can someone explain me this ?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
user3097712
  • 1,565
  • 6
  • 27
  • 49
  • 1
    If this is specifically about x86 assembly, you should tag it as such. – lurker Aug 28 '14 at 13:31
  • 2
    When you multiply EDX by EAX, the result is in `EDX:EAX`. `0330FD3B` * `95217CB1` is `1DBEE41EB22A9CB` so `EDX` would be `1DBEE41` and EAX would be `EB22A9CB` forming the entire answer. – lurker Aug 28 '14 at 13:35
  • 2
    Read the link you posted more carefully, OP :) – Al.Sal Aug 28 '14 at 13:36
  • Looks like this might be division by a constant, given how it's right shifting the high half of the result. [Why does GCC use multiplication by a strange number in implementing integer division?](https://stackoverflow.com/q/41183935) – Peter Cordes Jan 29 '21 at 21:37

2 Answers2

9

The description for MUL r/m32 is Unsigned multiply (EDX:EAX <- EAX * r/m32)..

That means that the 64-bit product will be stored in EDX:EAX, i.e. the upper 32 bits ends up in EDX and the lower 32 bits in EAX. Which fits with the results you're seeing, since the product should be 0x1DBEE41EB22A9CB.

Michael
  • 57,169
  • 9
  • 80
  • 125
4

Result is 01DBEE41 EB22A9CB, EDX stores high part of it.
Decimal numbers are not concatenatable when dealing with binary representation of numbers.

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64