Question

These are the 4 lines of assembly code. i am trying to understand them. (It is intel syntex.)

    – mov eax, ebx
    – mov eax, [ebx]
    – mov eax, [ebx+ecx*X] (X=1, 2, 4, 8)
    – mov eax, [ebx+ecx*X+Y] (Y= one byte, 0-255 or 4 bytes, 0-2^32-1)

1)The first line will copy whatever the value in ebx register to eax register. 2)The second line will find whatever the value in ebx register, teat it as a memory address, will go to that memory address. It will copy the value in that memory address to eax register. 3)The third line will get the value on ebx register, treat it as a memory address. Add ecx*X to it and will get a new address, and then go to this new address and get the value and copy it to eax. 4)I can't get the 4th line.

Can anyone just check, what I understood about the instructions are correct? If they are not correct, kindly explain me. Also explain the 4th line too.

Thanks in advance.

Was it helpful?

Solution

1-3)

Your assumptions look correct to me.

4)I can't get the 4th line.

It's the same as the 3rd one, except that an absolute offset is added. For example:

mov eax,[ebx+ecx*4+arrays]

arrays:
array1: dd 0,1,2,3
array2: dd 3,2,1,0

If you set ebx to 0 you'd read the ecx:th element of array1. If you set ebx to 16 (4 * sizeof(dword)) you'd read the ecx:th element of array2.

OTHER TIPS

The general formula for offset calculation on the x86 is,

Offset = Base + (Index * Scale) + Displacement

where, in your examples, ebx is the base, ecx is the index and X is the scale and Y is the displacement. You can think of (3) and (4) as being the same where (3) is just (4) with Y equal to 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top