title: Displaying text video memory at 0xb8000 without using the C library
body: <p>I have been writing kernel in C. I've been using the GCC cross-compiler, writing on a Windows system and targeting 16bit Real Mode. I don't have the C library available to write the kernel. I have started with some code which is suppose to print a character directly to the screen. Here is a function from <code>kernel.c</code>:</p>
  
  <pre><code>int main()
  {
    char *src = (char *)0xB8000000L;
    *src = 'M';
    src += 2;
    *src = 'D';
    return 0;
  }
  </code></pre>
  
  <p>I compiled my code using GCC with the parameter <code>-m16</code> to generate code that will run in real mode. I use these commands to generate my <code>kernel.bin</code>:</p>
  
  <pre><code>gcc -ffreestanding -c -m16 kernel.c -o kernel.o
  ld -Ttext 0x10000 -o kernel.pe kernel.o
  objcopy -O binary kernel.pe kernel.bin
  </code></pre>
  
  <p>Stack Overflow user <a href="https://stackoverflow.com/users/3857942/michael-petch">Michael Petch</a> solved my <a href="https://stackoverflow.com/q/37344575/3857942">linker problem</a> but commented the code itself is incorrect. He made this comment:</p>
  
  <blockquote>
    <p>Besides the linker problem, are you trying to convert old TurboC/MSVC 16-bit code to GCC? I find (char *)0xB8000000L suspicious. If it was a true 16-bit C compiler it might be okay if it was (char far *)0xB8000000L. GCC is not a true 16-bit C compiler and doesn't have a notion of old style far pointers. So even if you get this code to compile this may not do what you think it does, I'm assuming from the -m16 option with GCC you are trying to create a real-mode 16-bit kernel (rather than a protected mode one)?</p>
  </blockquote>
  
  <p>I have been trying to implement my own <code>printf</code> like function in C for my own operating system. The code I provided above is only a small extract of what I understand. I have created a bootloader in assembly(8086).</p>
  
  <p>Is Michael correct? If so, how can I resolve this problem and write directly to the video memory at <code>0xb8000</code>?</p>