-3
lea RAX var
mov [RAX] 12

If RAX is now pointing to the address of the 'var' variable. then what does [RAX] mean. ?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Minkwan
  • 21
  • 1
  • 1
  • [What do square brackets mean in x86 assembly?](https://stackoverflow.com/q/48608423/995714) – phuclv Aug 23 '21 at 11:59
  • 5
    You won't get very far as an assembly language programmer if you ignore the need for commas like that! – TonyK Aug 23 '21 at 12:29

1 Answers1

3

I am assuming you’re asking about Intel-style x86 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’

tony.ganchev
  • 596
  • 4
  • 14
  • 4
    In most assemblers, `mov [rax], 12` is an error: ambiguous operand-size. `You'd need `mov byte [rax], 12` to write just one addressable unit of memory. – Peter Cordes Aug 23 '21 at 13:48
  • Right, also my memories are from rusty old 16/32bit tasm / nasm. I think it was even byte ptr [rax] ...? – tony.ganchev Aug 23 '21 at 20:54
  • 2
    `byte ptr` is TASM / MASM (and GNU `.intel_syntax noprefix`). `byte` is NASM / FASM. https://stackoverflow.com/tags/intel-syntax/info / [When should I use size directives in x86?](https://stackoverflow.com/q/44577130) / [Determining when NASM can infer the size of the mov operation](https://stackoverflow.com/q/30959266) – Peter Cordes Aug 23 '21 at 21:22