16-bit C/C++ compiler

Programming, for all ages and all languages.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

16-bit C/C++ compiler

Post by Firestryke31 »

Hey everyone, I'm in a bit of a pickle. My OS can load and run programs, but writing anything non-trivial in ASM is a PITA. I've decided that I would like to start using C/C++, but I can't seem to find a 16-bit compiler that fits my requirements. I was hoping I might get some pointers from here. The compilers I could find were 32-bit only, or written in 8086 assembly, or 160MB. I just want something small and simple, and open source so I can port it to my OS once it's finally able to write files.

I would prefer if it could use 32-bit instructions (using the 66h prefix), but it's not 100% necessary. It would be best if the whole toolchain could fit on a floppy with room to spare, but once again, it's not a requirement.

I've considered writing my own, but writing a somewhat standards-compliant C++ compiler is not easy.

So, any help or am I going to have to go with OpenWatcom?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: 16-bit C/C++ compiler

Post by Solar »

Firestryke31 wrote:...writing a somewhat standards-compliant C++ compiler is not easy.
To my knowledge, there is only one standards-compliant C++ compiler in existence. Look at the GCC project, and after all those years and all those contributions, they're still not really "there".

A C compiler, while no mean feat, is something that could be done. A C++ compiler, as a one-man show? The only thing yet more complex is a full-blown operating system (according to SE Theory as I was taught)...
Every good solution is obvious once you've found it.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: 16-bit C/C++ compiler

Post by Firestryke31 »

I did say somewhat standards compliant, so anyhing that will compile general c++ code will be fine. I've googled "16-bit c compiler" and "i186 gcc" but nothing that fit my needs came up.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 16-bit C/C++ compiler

Post by Combuster »

There's Borland's Turbo C, and from what I heard Watcom has a real-mode compiler as well. But standards-compliance was a bit shaky at that time.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: 16-bit C/C++ compiler

Post by earlz »

Yea, watcom iirc was the only decent 16bit compiler I've seen.. I think their may have been another one though that I can't remember(one that worked on *nix well)
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: 16-bit C/C++ compiler

Post by M-Saunders »

Firestryke31 wrote:I did say somewhat standards compliant, so anyhing that will compile general c++ code will be fine. I've googled "16-bit c compiler" and "i186 gcc" but nothing that fit my needs came up.
If you're running Linux/Unix, you could try BCC (Dev86). It's a small compiler that can be used to generate 16-bit binaries (raw, without header, if necessary). One of the MikeOS contributors created a library for writing MikeOS programs in C using the Dev86 toolchain. It's available via some distros' package managers -- if not, see http://rdebath.nfshost.com

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: 16-bit C/C++ compiler

Post by Firestryke31 »

Unfortunately I use Windows, though I do use MinGW if that helps.

I've been considering making Socks a DOS... not "clone" but kind of like "clone++". This may influence compilers available, since I won't be using a homebrewed executable format.

Maybe this thread shouldn't be in the "Auto-delete" forum since it has all of these 16-bit compilers in it...
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: 16-bit C/C++ compiler

Post by Combuster »

Moved as per request
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: 16-bit C/C++ compiler

Post by Love4Boobies »

I plan to add real mode support to my C++ compiler since I'll also be using it for compiling my boot loader. Unfortunately right now it's not really usable - the code generated is far from optimized and in some cases even wrong. I do have full support for ELF and plain binary formats, though :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: 16-bit C/C++ compiler

Post by Brendan »

Hi,
M-Saunders wrote:If you're running Linux/Unix, you could try BCC (Dev86). It's a small compiler that can be used to generate 16-bit binaries (raw, without header, if necessary). One of the MikeOS contributors created a library for writing MikeOS programs in C using the Dev86 toolchain. It's available via some distros' package managers -- if not, see http://rdebath.nfshost.com
Just a quick note: BCC (Bruce's C Compiler, *not* Borland) works for the "tiny" memory model (where all code and data is in the same 64 KiB segment), but AFAIK it doesn't have any support for segmentation (unlike old 16-bit compilers that were used for DOS, which had support for far pointers and could use the "large" memory model).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: 16-bit C/C++ compiler

Post by bewing »

Firestryke31 wrote:... but writing anything non-trivial in ASM is a PITA.
You don't have to write code directly in ASM, or directly for the target platform. Write the code you want in C/C++, run it through whatever compiler on whatever platform you want, use objdump or whatever disassembler you want to dump the resulting ASM to a file, and then edit the ASM by hand to tidy it up/comment it/make it slick/make it run. I converted an entire JPG library to assembler that way, once, in under a week. It's a lot easier to work with ASM if you don't need to make up every line of code out of thin air.

And why don't you want to use something like TinyCC, or a nice old copy of MicroSquish's QuickC for compilations?

(And you will never find a C++ compiler that is small. There are too many and too complex features. C was designed to translate directly and easily into ASM. C++ never was.)
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: 16-bit C/C++ compiler

Post by Firestryke31 »

I posted this here so I could find a compiler that generates 16-bit code so I wouldn't have to do any hand-editing of assembly. I'm trying to get away from having to directly mess with assembly in anything that's not my main kernel. I've decided that, due to a switch in the goal of my O.S. any compiler that generated a MS-DOS .exe will work for my purposes.

Does TinyCC or MicroSquish's QuickC generate 16-bit assembly without me having to go through and modify them to do so myself?

I also did say that fitting on a floppy would have been nice but not a requirement.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: 16-bit C/C++ compiler

Post by bewing »

I'm pretty sure that's the ONLY thing that QuickC 2.0 produces. The date on the compiler is 1990. The help screens don't even show E?X registers -- I think the compiler predates the 386.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: 16-bit C/C++ compiler

Post by earlz »

tinycc doesn't compile for me on OpenBSD.. missing some weird ucontext.h file
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

Re: 16-bit C/C++ compiler

Post by kubeos »

There is a smallc compiler out therefor DOS. it came in nasm source form.
So you compiled it with nasm, then you had a 16 bit c compiler.
The compiler generates 16bit code that nasm can compile.
So it's self compiling, and was pretty damn small IIRC.
But I can't remember where I got it, and I don't have a backup.

But maybe someone here knows where to get it from.

There are also some 16-bit compilers out there by J.E. Hendrix that
work on DOS, but they use tasm, or masm... or something.
Post Reply