title: Iterate through string in memory in Assembly
body: <p>I'm having some troubles accessing each character of a string in turn in Assembly. I have the following code that calls the <code>print_string</code> routine, before declaring <code>'Hello World!', 0</code> into the <code>bx</code> registry:</p>
  
  <pre><code>mov bx, HELLO_MSG
  call print_string
  
  HELLO_MSG:
    db 'Hello, World!', 0
  </code></pre>
  
  <p>Within <code>print_string</code>, I'm able to print the first character of the string by doing this:</p>
  
  <pre><code>mov al, [bx]
  
  ; Trigger a single character print
  mov ah, 0x0e
  int 0x10
  </code></pre>
  
  <p>In my basic understanding of assembly, the address of the first character (<code>H</code>) got saved into <code>bx</code>, so by doing <code>mov al, [bx]</code> I'm dereferencing the pointer and assigning the real value of <code>H</code> into <code>al</code>.</p>
  
  <p>Based on that understanding (please correct me if I'm wrong) I've tried the following approaches:</p>
  
  <pre><code>mov cl, bx ; Move the pointer to `cl`
  add cl, 1 ; Do pointer arithmetic to add one byte to the address (hopefully referencing the next character)
  mov al, [cl] ; Dereference the address
  </code></pre>
  
  <p>But I got this error pointing to the <code>mov al, [cl]</code> line:</p>
  
  <pre><code>error: invalid effective address
  </code></pre>
  
  <p>I've also tried the following:</p>
  
  <pre><code>mov al, [bx] ; Move the dereferenced address to `al` (so `al` has `H`)
  add al, 1 ; Increment `al`, but of course I'm getting the ASCII value of `H` + 1, which is not the next character in the string.
  </code></pre>