Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the brackets mean in x86 asm?

Tags:

x86

assembly

nasm

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

like image 225
joek1975 Avatar asked Jan 08 '10 20:01

joek1975


People also ask

What do brackets do in ASM?

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.

What do [] mean in assembly?

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'

What do parentheses mean in x86?

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.

What do parenthesis around a register mean?

Means "the memory at the address that's stored in the register". Follow this answer to receive notifications.


1 Answers

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

like image 172
interjay Avatar answered Sep 30 '22 18:09

interjay