1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jamie
  • 1,092
  • 3
  • 22
  • 44

2 Answers2

3

Look up instructions such as LEA

Think of it this way:

LEA edx,[esi+ebx*4]
Daniel Goldberg
  • 19,908
  • 4
  • 21
  • 29
1

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.

Community
  • 1
  • 1
ruchir patwa
  • 311
  • 1
  • 5
  • 13