I have this project: Compile a C/C++ program to a CP/M-86 executable (CMD-file) with a modern compiler. The target architecture is 16-bit x86. You may think I am crazy but I am doing this for fun and to learn about CP/M-86 and low level x86 programming in general.
I have little to no knowledge about x86 assembler programming but I have done a "Hello World" example that I can use ASM86 and GENCMD to generate a CMD-file. And it works. ASM86 is an assembler program for CP/M-86 that will generate a H86-file, that is (as far as I understand) Intel Hex Code. GENCMD reads this HEX-file and creates the CMD executable. CMD is the CP/M-86 equivalent of EXE executables know from DOS and Windows.
I have a "modern" tool that will compile and link 16-bit x86 NASM code and output a working CMD that I can run on my CP/M-86 machine - build completely on my Linux machine. However, I need a C/C++ compiler that will create this compatible NASM code. Or maybe some kind of a flat binary that easily converts into a CMD.
The second thing is system calls. I can probably make a print-like function using inline assembly and test that. For now I just want to compile this program, that does not do anything (and hopefully does not do any system calls?):
int main()
{
return 0;
}
C compilers do exist for CP/M-86 but these are very, very old and pretty much unusable. Especially if I want to do C++, like I really want to. So, it has to be done with a modern compiler like gcc or llvm-clang or something like that.
A last resort could be compiling a 16-bit DOS-compatible EXE and then do some system call translation... but that will be kind of cheating and still be quite time consuming.
How can I reach my goal? Thanks in advance. Any advice is appreciated :-)