Use of brackets when specifying far pointers in Intel syntax assembly

jj1984

Member
I've been reading Intel's manual and I reviewed an old chapter this morning.

I found the following:

For example, the following MOV instruction moves a value from register EAX into the segment
pointed to by the ES register. The offset into the segment is contained in the EBX register:
MOV ES:[EBX], EAX;


I'm curious here about the use of the brackets around EBX.

The use of brackets used this way, around a register or memory location, is supposed be a dereferenced pointer.

That is, brackets used that way are supposed to mean "treat what's between these brackets as a pointer and go to the memory address that this pointer points to and manipulate what you find there."

But, in the above quote, Intel doesn't dereference the pionter.

In the above example, apparently, using [EBX] is the same as just using EBX.

When I see something like ES:[EBX], I think take EBX and treat it like it's a pointer that points somewhere in the active default data segment, DS.

Take what you find there and use that as the offset in the ES segment.

But, apparently that's not how it's done.

Why?

Is this just some quirk of the language syntax?

The only other place I've seen something like this is with the LEA, load effective address, machine instruction.

The LEA instruction looks like this I think: LEA register1, [expression usually containing registers]

Here, the expression in the brackets is not used to dereference the pointer.

It's just used in itself to move the calculated expression itself into register1.

Does the segment : offset syntax work the same way?
 

jj1984

Member
From the IA-32 manual:

Thanks, but that's my question.

Why, if the contents of register di hold the offset, are we using the brackets?

It should just be di by itself with no brackets.

Brackets mean dereference pointers.

But, we're not dereferencing pointers here to get the offset; the offset itself is directly in di already.

Is this just a syntactical thing?
 

Cromewell

Administrator
Staff member
It should just be di by itself with no brackets.
Yes, that's what I would expect to see as well. I suspect it's just a wording/editing issue.

If I saw MOV ES:[EBX], EAX; I would say EBX contains a memory address which contains the offset.
 

jj1984

Member
Yes, that's what I would expect to see as well. I suspect it's just a wording/editing issue.

If I saw MOV ES:[EBX], EAX; I would say EBX contains a memory address which contains the offset.

OK, so we agree.

It is possible, though, that this strange use of brackets is just syntactical.

Doesn't the LEA instruction work the same way?

Doesn't the LEA instruction take a dereferenced pointer and actually not dereference it, just use what's in the brackets itself as the argument?

Example: LEA eax, [ebx + 2*ecx]

That instruction would load eax with what the inside of the brackets evaluates to, not use the evaluation of the inside of the brackets as a pointer.

Right?
 

Cromewell

Administrator
Staff member
LEA eax, [ebx + 2*ecx]
Well lea works on memory addresses. The second operand is a memory address which is placed in eax. Memory management is complicated when you do it yourself, it's why not very many people write this stuff anymore.
 

jj1984

Member
Well lea works on memory addresses. The second operand is a memory address which is placed in eax. Memory management is complicated when you do it yourself, it's why not very many people write this stuff anymore.

Yes, but, LEA would compute ebx +2*ecx and put that value into eax.

Right?

It wouldn't take ebx +2*ecx and then treat it as a memory address and go there and take what's there and put it into eax.

Correct?

That is, it uses a dereferenced pointer as an argument but doesn't actually do
the dereferencing.
 

Cromewell

Administrator
Staff member
Yes. That said, it's consistent with commands working on a memory address, you put [] around something that's an address. If I said push [eax], I'm putting 4 bytes from the location pointed to in eax onto the stack. Or mov, or pretty much any command other than lea

I guess a safer general statement would be to say put you [] around a value which is a memory address, rather than saying it's a dereferencer - though that would usually be what happens.
 
Top