I’ve come across many programming languages. Each of them had their charm, but also a few things I disliked. Therefore I’m designing my own programming language and simply implement the things I liked in other languages.
After doing some of research, though mostly speculation, I believe I somewhat understand how processors and operating systems work. I managed to make an interpreter which reads and interprets instructions in a custom format I made using an instruction pointer and some (virtual) registers, and have been compiling code to that format for now.
However, this seems silly to me as my compiler now generates a binary to generate a binary and interpret it, and then interprets that. Though the current way of doing it does have some benefits (such as compiling just once and being able to run it almost everywhere), I’m curious about where to start when making a compiler that actually generates code the operating system can read.
I heard some things about PE and ELF, but have not been able to find anything that describes these formats at a low level. Most things seem to be about the great concepts it uses to do all sorts of stuff, but nothing seems to be structured in an understandable way such as firstly 16 bits of …, then 20 bits of …, then 28 of …, then the relocation table, then some instructions of which … means … etc.
Also, I use C++.
Here is an article about how to create tiny/simple PE files for Windows:
http://www.phreedom.org/research/tinype/
That article links to a guide for creating tiny/simple ELF files for Linux:
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
They both have lots of technical details about the file formats, and they both mention nasm and similar tools. I think the best way for you to accomplish your goals is going to be to generate assembly code and have nasm or another assembler create your executables.