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

user2443423 picture user2443423 · Sep 27, 2013 · Viewed 12.1k times · Source

I am writing real mode function, which should be normal function with stackframes and so, but it should use %sp instead of %esp. Is there some way to do it?

Answer

linguamachina picture linguamachina · Oct 8, 2015

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.