You are on page 1of 1

How OS is written:

All code that executes on a machine ultimately needs to run in machine code, so there's no
requirement that your code be in C or even something that compiles in C. Any language that
compiles to machine code, like Fortran, Haskell, or C++ could be used instead. If you're crazy and
want to write in pure machine code that's fine too.

The reason that gcc is written in C has to do with a process called bootstrapping. Before there was C
there was assembly, a very simple macro language that compiles more or less with a one-to-one
translation to machine code. The first assembler was written in machine code, but once it was
available it became possible to write the assembler in assembly, then use the old assembler to
compile a the new assembler as a replacement. From that point forward, you could write any
program you want to in assembly, and can enhance the assembler by writing new assembly code for
it. When it came time to write the first C compiler, it was first written in assembly and compiled to
machine code. Next, the compiler was rewritten in C and compiled using the assembly-based
compiler. Once the compiler was written in C, the compiler itself can be used to compile newer and
newer compilers written in C. Cool, huh?

You might also like