title: Basic use of immediates vs. square brackets in YASM/NASM x86 assembly
body: <p>Suppose I have the following declared:</p>
  
  <pre><code>section .bss
  buffer    resb     1
  </code></pre>
  
  <p>And these instructions follow in <code>section .text</code>:</p>
  
  <pre><code>mov    al, 5                    ; mov-immediate
  mov    [buffer], al             ; store
  mov    bl, [buffer]             ; load
  mov    cl, buffer               ; mov-immediate?
  </code></pre>
  
  <p>Am I correct in understanding that bl will contain the value 5, and cl will contain the memory address of the variable <code>buffer</code>?</p>
  
  <p>I am confused about the differences between </p>
  
  <ul>
  <li>moving an immediate into a register,</li>
  <li>moving a register into an immediate (what goes in, the data or the address?) and</li>
  <li>moving an immediate into a register without the brackets 
  
  <ul>
  <li>For example, <code>mov cl, buffer</code> vs <code>mov cl, [buffer]</code>  </li>
  </ul></li>
  </ul>
  
  <hr>
  
  <p>UPDATE: After reading the responses, I suppose the following summary is accurate:</p>
  
  <ul>
  <li><code>mov edi, array</code> puts the memory address of the zeroth array index in <code>edi</code>.  i.e. the label address.</li>
  <li><code>mov byte [edi], 3</code> puts the VALUE 3 into the zeroth index of the array</li>
  <li>after <code>add edi, 3</code>, <code>edi</code> now contains the memory address of the 3rd index of the array</li>
  <li><code>mov al, [array]</code> loads the DATA at the zeroth index into <code>al</code>.</li>
  <li><code>mov al, [array+3]</code> loads the DATA at the third index into <code>al</code>.</li>
  <li><code>mov [al], [array]</code> is invalid because <a href="https://stackoverflow.com/questions/1299077/assembly-moving-between-two-memory-addresses/53470709#53470709">x86 can't encode 2 explicit memory operands</a>, and because <code>al</code> is only 8 bits and can't be used even in a 16-bit addressing mode.  <a href="https://stackoverflow.com/questions/34058101/referencing-the-contents-of-a-memory-location-x86-addressing-modes">Referencing the contents of a memory location. (x86 addressing modes)</a></li>
  <li><code>mov array, 3</code> is invalid, because you can't say "Hey, I don't like the offset at which <code>array</code> is stored, so I'll call it 3".  An immediate can only be a source operand.</li>
  <li><code>mov byte [array], 3</code> puts the value 3 into the zeroth index (first byte) of the array.  <a href="https://stackoverflow.com/questions/44577130/when-should-i-use-size-directives-in-x86">The <code>byte</code> specifier is needed</a> to avoid ambiguity between byte/word/dword for instructions with  memory, immediate operands.  That would be an assemble-time error (ambiguous operand size) otherwise.</li>
  </ul>
  
  <p>Please mention if any of these is false.  (editor's note: I fixed syntax errors / ambiguities so the valid ones actually <em>are</em> valid NASM syntax.  And linked other Q&amp;As for details)</p>