68

Given the following code:

L1     db    "word", 0

       mov   al, [L1]
       mov   eax, L1

What do the brackets ([L1]) represent?

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
joek1975
  • 3,303
  • 5
  • 36
  • 44

8 Answers8

56

[L1] means the memory contents at address L1. After running mov al, [L1] here, The al register will receive the byte at address L1 (the letter 'w').

interjay
  • 97,531
  • 20
  • 242
  • 238
  • 9
    Thanks for your reply, I am starting to learn asm. If I understand this correctly, "mov al, [L1]" would move 'w' into al, and "mov eax, L1" would move the address of L1 into eax. Is that correct? – joek1975 Jan 08 '10 at 20:35
  • 7
    yes. and if you did `mov ebx,L1 -- mov al,[ebx]` then `al` would be 'w' in that case too. – Earlz Jan 08 '10 at 21:35
  • 4
    The exception to this is LEA. – Natan Yellin Nov 04 '11 at 13:56
  • @interjay, So why is it that the brackets are not needed in the second line: `mov eax, L1`? – Pacerier May 17 '17 at 18:27
  • 1
    @Pacerier It depends on the assembler you're using, but usually without the brackets it will get the memory address, not the contents. – interjay May 17 '17 at 21:09
52

Operands of this type, such as [ebp], are called memory operands.

All the answers here are good, but I see that none tells about the caveat in following this as a rigid rule - if brackets, then dereference, except when it's the lea instruction.

lea is an exception to the above rule. Say we've

mov eax, [ebp - 4]

The value of ebp is subtracted by 4 and the brackets indicate that the resulting value is taken as an address and the value residing at that address is stored in eax. However, in lea's case, the brackets wouldn't mean that:

lea eax, [ebp - 4]

The value of ebp is subtracted by 4 and the resulting value is stored in eax. This instruction would just calculate the address and store the calculated value in the destination register. See What is the difference between MOV and LEA? for further details.

legends2k
  • 27,643
  • 22
  • 108
  • 196
  • 1
    The first link is dead. Here is a snapshot: https://web.archive.org/web/20180331051340/http://www.imada.sdu.dk/Courses/DM18/Litteratur/IntelnATT.htm – Hritik May 07 '20 at 10:01
  • @Hritik Thanks for flagging the broken link! Fixed with a better link :) – legends2k May 07 '20 at 14:15
30

Simply means to get the memory at the address marked by the label L1.

If you like C, then think of it like this: [L1] is the same as *L1

Earlz
  • 57,517
  • 89
  • 275
  • 484
  • this can be confusing since in C `*p` means that _dereference p and stop retrieving chars when you'll reach `\0`_ and not just _dereference the first char in the sequence/string pointed by p_ – user2485710 Sep 13 '14 at 14:40
  • 23
    @user2485710 No, `*p` means dereference the char pointed by `p`. Strings have nothing to do with this. – Navin May 01 '16 at 00:29
9

The brackets mean to de-reference an address. For example

mov eax, [1234]

means, mov the contents of address 1234 to EAX. So:

1234 00001

EAX will contain 00001.

user157251
  • 64,489
  • 38
  • 208
  • 350
Jason Evans
  • 28,042
  • 13
  • 88
  • 145
2

Direct memory addressing - al will be loaded with the value located at memory address L1.

legends2k
  • 27,643
  • 22
  • 108
  • 196
John Dibling
  • 94,084
  • 27
  • 171
  • 303
1

As with many assembler languages, this means indirection. In other words, the first mov loads al with the contents of L1 (the byte 'w' in other words), not the address.

Your second mov actually loads eax with the address L1 and you can later dereference that to get or set its content.

In both those cases, L1 is conceptually considered to be the address.

paxdiablo
  • 772,407
  • 210
  • 1,477
  • 1,841
1

They mean that instead of moving the value of the register or numeric value L1 into the register al, treat the register value or numeric value L1 as a pointer into memory, fetch the contents of that memory address, and move that contents into al.

In this instance, L1 is a memory location, but the same logic would apply if a register name was in the brackets:

mov al, [ebx]

Also known as a load.

Alex Brown
  • 38,674
  • 9
  • 88
  • 106
0

It indicates that the register should be used as a pointer for the actual location, instead of acting upon the register itself.

Ignacio Vazquez-Abrams
  • 699,552
  • 132
  • 1,235
  • 1,283