flat assembler
Message board for the users of flat assembler.
Index
> Main > imul vs. mul |
Author |
|
comrade 17 Dec 2005, 20:52
you should edx too, the result is 64-bit stored in edx:eax
and yes, 8*-8=64 what's with the !? |
|||
17 Dec 2005, 20:52 |
|
Tomasz Grysztar 17 Dec 2005, 22:54
When multiplying N-bit number by other N-bit one, the low N bits of the result are the same no matter whether you do the signed or unsigned multiplication - you can read first chapter of my tutorial, which I have written to explain such things (though I'm not sure whether I wrote it clearly enough there, if you have any suggestions or questions, please let me know).
So both 32-bit MUL and IMUL produce the same low 32 bits of result. For this reason though there are additional variants of IMUL that can store result in any 32-bit register or memory location, there are no such for MUL, since they would do exactly the same. The difference is in case when the result is stored as 64 bits in EDX:EAX, and high 32 bits (in EDX) may differ. |
|||
17 Dec 2005, 22:54 |
|
Plue 18 Dec 2005, 07:45
> you should edx too, the result is 64-bit stored in edx:eax
But what if I only have a 4-byte integer to but the result into? > and yes, 8*-8=64 But I get -64? > what's with the !? Oh, sorry, it's inline assembly from another programming language. Forgot to remove them. |
|||
18 Dec 2005, 07:45 |
|
Madis731 19 Dec 2005, 13:50
You should always assume that DWORDxDWORD=QWORD and preserve 8 bytes. If you are really sure that there is no result larger than 4.2billion then you can ignore EDX and use only EAX.
Why imul? Well, you can use all kinds of interesting modifiers Code: ;You can only do: mul reg mul mem ;But with imul you can do: imul reg imul mem imul reg, reg, immediate imul reg, mem, immediate imul reg, immediate imul reg, reg imul reg, mem ;So this is perfectly legal: imul eax,[eax+8*edx+402000h],2147483647 ;13 bytes ;...but this gives an error: mul eax,[eax+8*edx+402000h],2147483647 With imul you can define your source address or register, the multiplicand and the destination. MUL takes eax by default (edx also gets modified) and you can only multiply it with another register or memory address, but not a constant. |
|||
19 Dec 2005, 13:50 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.