Brackets on registers in Intel x86 assembly syntax

assembly, cpu-registers, nasm, syntax, x86

Solution

The bracket notation is used to let you access the "value pointed to" by the register or label.

mov ax, [LABEL]

LABEL:
db "X", 0

You are loading `ax` with the value from the memory labeled by `LABEL`. In this case, you are copying the 'X' (0x58 ASCII) into the `ax` register, along with the `0` into the high byte of `ax`. So `ax = 0x0058`, with `ah = 0`, `al = 0x58`.

`LABEL` is attached to the address where "X" is located.

This is not a valid operation:

mov al, ebx

And this:

mov [edx], ax

You are moving the value of `ax` into the first two bytes of "the value pointed to by `edx`", since `ax` is a 16 bit register and `edx` is just holding the memory address where it should be written to.

Problem

I tought I understood brackets in x86 assembly. In this example, the register `ax` should contain `X`, because brackets represents the current address of `LABEL`. ``` mov ax, [LABEL] LABEL: db "X", 0 ``` But I dont understand the following two assembly lines: ``` mov al, [ebx] ``` Why do I need brackets? Is it because `ebx` is a 32 bits register and `ax` a 16 bits? Whats the difference with: ``` mov al, ebx ``` Or this one, I don't understand why I need brackets... ``` mov [edx], ax ```

Original source

Related problems