Page 1 of 2

16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 10:01 am
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?

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 11:57 am
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)...

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 12:03 pm
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.

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 12:15 pm
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.

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 1:49 pm
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)

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 3:22 pm
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

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 3:33 pm
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...

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 4:04 pm
by Combuster
Moved as per request

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 5:49 pm
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 :)

Re: 16-bit C/C++ compiler

Posted: Wed Apr 22, 2009 7:08 pm
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

Re: 16-bit C/C++ compiler

Posted: Fri Apr 24, 2009 12:59 pm
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.)

Re: 16-bit C/C++ compiler

Posted: Fri Apr 24, 2009 5:18 pm
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.

Re: 16-bit C/C++ compiler

Posted: Fri Apr 24, 2009 9:14 pm
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.

Re: 16-bit C/C++ compiler

Posted: Fri Apr 24, 2009 9:38 pm
by earlz
tinycc doesn't compile for me on OpenBSD.. missing some weird ucontext.h file

Re: 16-bit C/C++ compiler

Posted: Tue May 05, 2009 5:43 pm
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.