I've got the address of my array (passed as a pointer to the function) in esi register. How can I access a particular cell of the array? i.e:
my_array[a + b * c]
where c
is constant.
You could directly move it as follows also:
MOV EDX, [ESI + 4*EBX]
For a static array, you can actually use two registers at once to index it, but using the array base address as the 32-bit displacement in the addressing mode. This only works for non-position-independent code.
MOV EDX, my_array[ECX + 4*EBX]
Instead of using two different registers, you can use the same register twice to simulate a scale factor of 3 (ebx + ebx*2
), 5, or 9.