I have a very naive question here, and I would like you to correct me on whatever wrong concepts I put out here. The question is as follows:
I have ubuntu installed on my machine, now I write a helloWorld.c program in C language. Now, on the operating system I have a compiler installed, when I execute my helloWorld.c program, the OS schedules the compiler and that basically compiles my code into machine code, which eventually, I execute.
Now my kernel code is written in C, then how does my machine interprets that code? Say my kernel code is helloWorld.c, now would not I require any compiler, to compile this code. Also, if I hardcode a compiler in maybe ROM or something, then what language is it written in? Assembly language?
Let me know if I have made myself clear with the problem.
Thanks.
EDIT: By kernel code I mean, the code for operating system. Operating System code. I guess it is written in C right?
I think the crux of your question is a kind of chicken-n-egg problem for compilers.
Nowadays we have compilers available. So when one develops a newer version of a compiler (say gcc4.7) written in C, then one first uses an older version of the compiler to build it. i.e. gcc4.6(which already exists) will be used to compile the code and generate the latest version i.e. gcc4.7.
This can be traced all the way back to the first compiler ever which as you rightly mention would have required extensive amount of coding in assembly.
You might want to take a look at this discussion on the bootstrapping & history of the 1st compiler.
UPDATE :
Also a fairly common way to get the “first” OS+compiler running is cross-compilation. Here is a nice description of what all one needs to and how one goes about it. In engineering circles this process is called “porting” an OS to a specific device/architecture.
Essentially the first bare-bones one needs to have :