问题
I have looked all over the internet for a simple-to-understand evaluation of how to multiply and divide in masm32 assembly. My questions are:
Where should I place the numbers being multiplied?
Where should I place the numbers being divided?
Where does the remainder go in the division?
Could someone please answer this for me?
Thanks,
Progrmr
回答1:
The answer to this question can be very easily found by looking at the proper page of the Intel 64 and IA-32 Instruction Set Reference. In this case, you're looking for the MUL
and DIV
instructions (in case you're operating on unsigned operands) or IMUL
and IDIV
instructions, which are used for signed integer multiplication and division.
So, in case you really don't feel like looking through the manual :
- One of the operands of the multiplication must be placed in the
EAX
register if you're usingMUL
. This is a bit more flexible if you're using theIMUL
instruction, which allows you to specify the source and destination registers. - The number being divided is always a 64-bit number in 32-bit mode. The high bits go into
EDX
, while the lower bits go intoEAX
. - The remainder is always placed in
EDX
.
来源:https://stackoverflow.com/questions/10684736/x86-assembly-masm32-absolute-breakdown-of-multiplication-and-division