0

What does the operation

movl (%esi, %ecx,4), %eax do?

To my understanding it would store in %eax the equivalent of %ecx * 4 + %esi.

0

2 Answers 2

3

It's equivalent to the following in Intel syntax:

mov eax,[esi + ecx*4]

What it will do is read 32 bits from memory at the address formed by esi + ecx*4 and put that value in eax.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that you can get objdump to output Intel syntax with objdump -d -M intel
1

Yes, you are write.
It is called as the index addressing mode.

It's syntax is:

<constant1/label> (%reg1, %reg2, constant2)

i.e. either constant1 or label without < & >.

%reg1 and %reg2 must be GPRs.
<constant1/label> is optional.
%reg1 is optional.

It results in: constant1 + %reg1 + %reg2 * constant2

Generally, constant1 or label and %reg1 are used for the base address of an array. And %reg2 & constant2 are used for the index.

For example:

Let's say, you have a global array:

.section .data
    .globl   arr
    .type    arr,    @object
    .size    arr,    20
    .align   4
arr:
    .long    10, 20, 30, 40, 50

Then you may write...

movl    $2,    %eax                # Move the index into %eax
movl    arr( , %eax, 4),    %edx

This means: %edx = arr + %eax * 4. i.e. Base address + 8 bytes.
You may think of it like %edx = arr[2]

Generally,

If you have a global array having a lable, then you use label for the base address.
If you have a local array, then you use the %reg2 fot the base address.
If you have a global structure containing array, then you use both label of the structure + %reg2 containing the byte-offset of the member array.

That's what happens generally... but it depends on the situation...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.