What do the brackets mean in x86 asm?

前端 未结 8 1853
旧时难觅i
旧时难觅i 2020-11-30 20:51

Given the following code:

L1     db    \"word\", 0

       mov   al, [L1]
       mov   eax, L1

What do the brackets ([L1]) represent?

相关标签:
8条回答
  • 2020-11-30 21:08

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

    0 讨论(0)
  • 2020-11-30 21:09

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

    0 讨论(0)
  • 2020-11-30 21:14

    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

    0 讨论(0)
  • 2020-11-30 21:15

    [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').

    0 讨论(0)
  • 2020-11-30 21:17

    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.

    0 讨论(0)
  • 2020-11-30 21:18

    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.

    0 讨论(0)
提交回复
热议问题