How was the first compiler written?

Shawn Mclean picture Shawn Mclean · Oct 31, 2009 · Viewed 46.3k times · Source

I heard about the chicken and the egg and bootstrapping. I have a few questions.

What wrote the first compiler that converted something into binary instructions?

Is assembly compiled or translated into binary instructions?

...I'd find it hard to believe they wrote a compiler in binary.

Answer

Amber picture Amber · Oct 31, 2009

Assembly instructions are (generally) a direct mapping to opcodes, which are (multi-)byte values of machine code that can be directly interpreted by the processor. It is quite possible to write a program in opcodes directly by looking them up from a table (such as this one for the 6039 microprocessor, for example) that lists them with the matching assembly instructions, and hand-determining memory addresses/offsets for things like jumps.

The first programs were done in exactly this fashion - hand-written opcodes.

However, most of the time it's simpler to use an assembler to "compile" assembly code, which automatically does these opcode lookups, as well as being helpful in computing addresses/offsets for named jump labels, et cetera.

The first assemblers were written by hand. Those assemblers could then be used to assemble more complicated assemblers, which could then be use to assemble compilers written for higher-level languages, and so on. This process of iteratively writing the tools to simplify the creation of the next set of tools is called (as mentioned by David Rabinowitz in his answer) bootstrapping.