The IA32 assembler operand for x[i] used the scaled index form where x is an int array.
(%eax, %edx, 4)
%eax contains the beginning address of arrray x
%edx contains the value of i
4 multiplier
address: contentsOf(%eax) + 4 * contentsOf(%edx)
The index i can't just be added to the address of x to get the address of x[i] since the size of each int is 4 bytes.
For example, the address of x[1] is not 0x8001, but is 0x8004:
| Element | i | Address |
|---|---|---|
| x[0] | 0 | 0x8000 |
| x[1] | 1 | 0x8004 |
| x[2] | 2 | 0x8008 |
| x[3] | 3 | 0x800C |
So i must be multiplied by this size 4 and then added.
Using scaled index operand does the multiplication without needing a separate imull instruction.