title: NASM on DOS (Intel 8086): invalid effective address
body: <p>I am writing code for DOS using Bochs. I am compiling the program using <strong>NASM</strong><br>
  Lets suppose i have the following code:</p>
  
  <pre><code>[BITS 16]
  
      SEGMENT code
  
  ..start:
  mov ax, data
  mov ds, ax
  mov bx, msg
  mov al, byte [bx]
  int 21h
  
      SEGMENT data
  
  msg  DB "teststring", 00h
  </code></pre>
  
  <p>Why is it that nasm complains on the line:</p>
  
  <pre><code>mov al, byte [bx]
  </code></pre>
  
  <p>of <strong>invalid effective address</strong>?</p>
  
  <p>If instead of using <strong>bx</strong> i use the <strong>si</strong> registry, the program compiles an works as supposed, loading the ascii value of <strong>t</strong> in <strong>al</strong>.</p>
  
  <p>Why is it?</p>
  
  <p>EDIT: Found that I can't use BX for indexing.<br>
  If I wanted to load what's pointed in a determined part of the data segment, you could do the following:</p>
  
  <pre><code>mov ax, data
  mov ds, ax
  mov si, msg
  mov al, byte [si] ; Loading first char
  inc si
  mov al, byte [si] ; Loading second char
  </code></pre>
  
  <p>If I wanted to keep <strong>si</strong> pointing to the start of the string, i could then use BX to be the offset:</p>
  
  <pre><code>mov al, byte [si + bx]
  </code></pre>
  
  <p>or even</p>
  
  <pre><code>mov al, byte [si + n] ; where n is an integer value
  </code></pre>
  
  <p>But to my understanding, bx could also be used, so the problem still resides.</p>