Given the following code:
L1 db "word", 0 mov al, [L1] mov eax, L1
What do the brackets in [L1]
represent?
This question is specifically about NASM. The other major flavour of Intel-syntax assembly is MASM style, where brackets work differently when there's no register involved:
See Confusing brackets in MASM32
Square brackets — the operand is an indirect address. If the operand is enclosed in square brackets, the assembler treats the operand as an indirect address; that is, it uses the contents of the operand as an address.
Square brackets means 'the variable at the memory address stored in RAX”. So: mov RAX, 12. means “store value 12 into RAX” mov [RAX], 12. means “store value 12 in the memory cell whose address is stored in RAX'
The parentheses indicate the move instruction should consider the value in rbp to be a memory address, that it should move the value 42 to the memory address referenced by rbp (or actually to the memory address four bytes before the value of rbp ) and not into rbp itself.
Means "the memory at the address that's stored in the register". Follow this answer to receive notifications.
[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').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With