title: How to use GDB in 16-bit mode?
body: <p>I have the following code, where I am trying to implement a function that prints string using the BIOS functions:</p>
  
  <pre><code>int printString(char* string)
  {
   int i = 0;
   while (*(string + i) != '\0')
     {
      char al = *(string + i);
      char ah = 0xe;
      int ax = ah * 256 + al;
      interrupt(0x10,ax,0,0,0);
      i++;
     }
   return i;
  }
  </code></pre>
  
  <p>The function interrupt is implemented in assembly. It calls the appropriate BIOS interrupt, as given by the first argument, with rest of the arguments containing the contents for ax,bx,cx and dx register respectively:</p>
  
  <pre><code>.global _interrupt
  _interrupt:
  push bp
  mov bp, sp
  push si
  push ds
  mov ax, #0x100
  mov ds, ax
  mov ax, [bp + 0x4]
  mov si, #intr
  mov [si + 1], al
  pop ds
  mov ax, [bp + 0x6]
  mov bx, [bp + 0x8]
  mov cx, [bp + 0xa]
  mov dx, [bp + 0xc]
  intr: int #0x0
  pop si
  pop bp
  ret
  </code></pre>
  
  <p>Since I am using BIOS interrupts I am using 16-bit mode to compile this code. I used the following command:</p>
  
  <pre><code>bcc -ansi -c -o printString.o printString.c
  </code></pre>
  
  <p>I want to test this code in GDB, but when I try to load this printString.o file into gdb using:</p>
  
  <pre><code>gdb printString.o
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p>"/home/kern/printString.o": not in executable format: File format not recognized</p>
  
  <p>I also tried changing the GDB to 16-bit format using:</p>
  
  <pre><code>set architecture i8086
  </code></pre>
  
  <p>But still this error is coming. How can I load a 16-bit code into GDB?</p>