title: Reading from memory in 8086 real mode while using 'ORG 0x0000'
body: <p>I've been messing around with x86-16 assembly and running it with VirtualBox. For some reason when I read from memory and try to print it as a character, I get completely different results from what I was expecting. However when I hard-code the character as part of the instruction, it works fine.
  Here's the code:</p>
  
  <pre><code>ORG 0
  BITS 16
  
  push word 0xB800        ; Address of text screen video memory in real mode for colored monitors
  push cs
  pop ds                  ; ds = cs
  pop es                  ; es = 0xB800
  jmp start
  
  ; input = di (position*2), ax (character and attributes)
  putchar:
      stosw
      ret
  
  ; input = si (NUL-terminated string)
  print:
      cli
      cld
      .nextChar:
          lodsb   ; mov al, [ds:si] ; si += 1
          test al, al
          jz .finish
          call putchar
          jmp .nextChar
      .finish:
          sti
          ret
  
  start:
      mov ah, 0x0E
      mov di, 8
  
      ; should print P
      mov al, byte [msg]
      call putchar
  
      ; should print A
      mov al, byte [msg + 1]
      call putchar
  
      ; should print O
      mov al, byte [msg + 2]
      call putchar
  
      ; should print !
      mov al, byte [msg + 3]
      call putchar
  
      ; should print X
      mov al, 'X'
      call putchar
  
      ; should print Y
      mov al, 'Y'
      call putchar
  
      cli
      hlt
  
  msg: db 'PAO!', 0
  
  ; Fill the rest of the bytes upto byte 510 with 0s
  times 510 - ($ - $$) db 0
  
  ; Header
  db 0x55
  db 0xAA
  </code></pre>
  
  <p>The print label and instructions in it can be ignored since I haven't used it yet because of the problem I've been having trying to print a character stored in memory. I've assembled it with both FASM and NASM and have the same problem meaning it's obviously my fault.</p>
  
  <p>It prints something like:
  <a href="https://i.stack.imgur.com/tziF4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tziF4.png" alt="VirtualBox"></a></p>