How was the first computer program created?

The short answer: the first programs were meticulously written in raw machine code, and everything was built up from there.

The idea is called bootstrapping. Suppose that you have a bare machine with a processor, some flash memory, and a hard disk. Typically, the processor is configured on power-up to load a simple operating system called the bootloader from a fixed location in non-volatile memory (for example, CMOS or flash). This OS is extraordinarily simple and has just enough functionality to point the computer to the spot on disk where the real OS lives. This OS can then turn on more and more devices and load more and more complicated programs, until eventually the whole OS is up and running.

But what is this bootloader written in? Originally, these were written in raw machine code and hardcoded into the machine. The programs it would run would be written in machine code as well, which would be unbelievably slow and tedious to work with. Eventually, someone wrote the first simple assembler in machine code. Once you have this assembler, you can start writing programs in assembly, including the assembler itself. In fact, once you have a simple assembler, you never need to write machine code again. You can just keep writing the assembler in assembly!

From this point you can build more complex programming languages by first writing the compiler using existing tools (the assembler, for example) to get just enough functionality available so that the compiler can do basic programming. You then use that compiler to write a compiler for the programming language itself, and use the same trick to build off of your previous work to get something bigger and cooler. This technique is still used today - most compilers are written in the language they compile to.

To summarize, everything had to be done by hand at some awful point in the past, but thanks to the hard work of the people who did this we can build off of what's already there.


In the early days of the microcomputer industry, we had to laboriously enter machine code directly using toggle switches. This was very similar to the way the first non-hardcoded-program computers were done.

See here for details on the early Altair machines. Basically, you set the binary switches for the address and data then used a command switch to write that to memory. Yes, one byte at a time. We were "real men" back then :-)

From that same site is the detailed process used to enter a sample program.

You should also keep in mind that you don't have to compile programs for machine X actually on machine X. Once machines reached a certain level of sophistication (where, for example, machine Y could run without toggling in programs), you could use cross-assemblers and cross-compilers to actually create the machine language for machine X.

Then you just needed a way to get the binary image of that program into machine X. It wasn't always easy but it was a darn sight easier than toggling switches.