title: How to disassemble 16-bit x86 boot sector code in GDB with "x/i $pc"? It gets treated as 32-bit
body: <p>For example, with a boot sector that BIOS prints <code>a</code> to the screen <code>main.asm</code>:</p>
  
  <pre><code>org 0x7c00
  bits 16
  cli
  mov ax, 0x0E61
  int 0x10
  hlt
  times 510 - ($-$$) db 0
  dw 0xaa55
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>nasm -o main.img main.asm
  qemu-system-i386 -hda main.img -S -s &amp;
  gdb -ex 'target remote localhost:1234' \
      -ex 'break *0x7c00' \
      -ex 'continue' \
      -ex 'x/3i $pc'
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>0x7c00:      cli    
  0x7c01:      mov    $0x10cd0e61,%eax
  0x7c06:      hlt 
  </code></pre>
  
  <p>So it looks like the <code>mov ax, 0x0E61</code> was interpreted as a 32-bit <code>mov %eax</code> and ate up the next instruction <code>int 0x10</code> as data.</p>
  
  <p>How can I tell GDB that this is 16-bit code?</p>
  
  <p>See also:</p>
  
  <ul>
  <li>in 2007 a GDB dev replied "use <code>objdump</code>" <a href="https://www.sourceware.org/ml/gdb/2007-03/msg00308.html" rel="noreferrer">https://www.sourceware.org/ml/gdb/2007-03/msg00308.html</a> as explained at <a href="https://stackoverflow.com/questions/1737095/how-do-i-disassemble-raw-x86-code">How do I disassemble raw x86 code?</a> Maybe it was implemented meantime?</li>
  <li>superset: <a href="https://stackoverflow.com/questions/28811811/using-gdb-in-16-bit-mode">Using GDB in 16-bit mode</a></li>
  <li>similar, but the OP got an error there, so maybe it is something else? <a href="https://stackoverflow.com/questions/10999988/how-can-i-disassembly-win16-with-gdb">How can I disassembly win16 with GDB</a> </li>
  </ul>