How to tell GCC to generate 16-bit code for real mode

GCC 5.2.0 (and possible earlier versions) support 16-bit code generation with the -m16 flag. However, the code will almost certainly rely on 32-bit processor features (such as 32-bit wide registers), so you should check the generated assembly carefully.

From the man pages:

The -m16 option is the same as -m32, except for that it outputs the
“.code16gcc” assembly directive at the beginning of the assembly output
so that the binary can run in 16-bit mode.

Leave a Comment