Question

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:

  1. Where should I place the numbers being multiplied?

  2. Where should I place the numbers being divided?

  3. Where does the remainder go in the division?

Could someone please answer this for me?

Thanks,

Progrmr

Was it helpful?

Solution

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 :

  1. One of the operands of the multiplication must be placed in the EAX register if you're using MUL. This is a bit more flexible if you're using the IMUL instruction, which allows you to specify the source and destination registers.
  2. 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 into EAX.
  3. The remainder is always placed in EDX.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top