Re: Is it catachrestial as 'Effective Addresses' in NASM documentation?



pzgyuanf@xxxxxxxxxxxx wrote:
The '3.3 Effective Addresses' section of Nasm doc really block me,
after reading 'Beginner question about arrays'

The 'Effective Addresses' in Nasm isn't that 'LEA-Load Effective
Address' in Intel 253666.pdf,
the former is the content of the memory, but the latter is memory
address (offset part).

So, I'm a beginner of ASM, appreciate your detail this catachrestial.

Frank Kotler, thank you for your explanation in 'Beginner question
about arrays' .

pipi

An effective address is simply the address that's actually used to
address memory. It's the end result of an expression that could be as
simple as a direct address:

mem dd 1,2,3,4,5
mov eax,[mem] ; eax = 1

To an offset from that direct address:

mov eax,[mem+4] ; eax = 2

To an indirect address using a register:

mov ebx,mem
mov eax,[ebx+4] ; eax = 2

To an indirect base+index*scale expression:

mov ebx,mem
mov esi,2
mov eax,[ebx+esi*4] ; eax = 3

The thing in the square brackets is an effective address expression,
and the result of the expression is an effective address, but everyone
just calls the expression an effective address.

Now, what might be confusing you is how lea behaves. It basically gives
you the address of the contents at the effective address, or the result
of the effective address expression. Using a fictional syntax, lea does
this:

mov ebx,mem
mov esi,2
mov edx,ebx+esi*4 ; Not valid syntax
mov eax,[edx] ; eax = 3

But that's not legal NASM syntax. Alternatively, you can do the same
thing using valid runtime operations, but it's far less elegant, and
one can easily see why lea exists:

mov ebx,mem
mov esi,2

; Simulate "lea edx[ebx+esi*4]"
mov edx,ebx
imul esi,4
add edx,esi
mov eax,[edx] ; eax = 3

.