Move address to register by using the indexed addressing mode

1.6k views Asked by At

Is it possible to calculate an address by using the indexed addressing mode syntax and store it into a register? Something like the following (wrong) expression (in AT&T assembly syntax):

movl $dataarray(,%edi,8), %eax

I know that the indexed addressing mode can be used to move data:

movl dataarray(,%edi,8), %eax

However, in this case, what I want to do is to store the address of the element of dataarray indexed by %edi into the %eax register.

1

There are 1 answers

1
ロウリン On BEST ANSWER

As already suggested in this comment, the lea instruction can be used for that purpose:

leal dataarray(,%edi,8), %eax

This way, the address (and not the value at that address, as it occurs with the mov instruction) is computed and stored into the eax register.