Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 872
user2443423 Avatar asked Sep 27 '13 16:09

user2443423


1 Answers

GCC does not produce 8086 code. The GNU AS directive .code16gcc can be used to assemble the output of GCC to run in a 16-bit mode, put asm(".code16gcc") at the start of your C source, your program will be limited to 64Kibytes.

On modern GCC versions you can pass the -m16 argument to gcc which will produce code to run in a 16-bit mode. It still requires a 386 or later.

like image 162
Timothy Baldwin Avatar answered Oct 03 '22 05:10

Timothy Baldwin