What exactly does the 3 operand imul instruction do in ia-32 assembly?

Rowhawn picture Rowhawn · Oct 5, 2010 · Viewed 7.5k times · Source

I'm reading the instruction

imul 0xffffffd4(%ebp, %ebx, 4), %eax

and I'm baffled by what it's doing exactly. I understand that imul multiplies, but I can't figure out the syntax.

Answer

Zooba picture Zooba · Oct 5, 2010

(I know and prefer Intel/MASM syntax, so I will use that. Note that the order of operands is different to AT&T.)

Your instruction is actually a two-operand imul, which in Intel syntax is:

imul eax, DWORD PTR [ebp + ebx*4 + 0FFFFFFD4h]

Where eax is the destination operand and the memory location is the source operand. The two-operand imul performs a signed (twos-complement) multiplication of the source and destination operands and stores the result in the destination.

This instruction is multiplying a register by the integer in an array. Most likely this appears in a loop and the array is a local variable.


The three-operand imul instruction is:

imul dest, source1, source2

The source1 operand (either a memory location or a register) is multiplied by the source2 operand (either an 8-bit or 16/32-bit integer) and the result is stored in the dest operand (a 16, 32 or 64-bit register).