OT: kernel in C? how translated? [Was Re: Help]
Samuel:
I've changed your subject line to something more meaningful, and have
routed it back to the list so that others who actually know these things
can address your questions; I'm not a programmer, and have never delved
into the inner workings of the kernel. However, this is also somewhat
off-topic for the Debian list so it's marked "OT"; still, some of the
fine folks on this list might can address your question and perhaps
steer you towards resources that are better suited for your questions.
samuel prakash wrote:
I have read that kernel is the real operating system and linux is the
name of the kernel.
The kernel is the core of the operating system. The operating system is
composed of the kernel and any utilities that ride on top of that
kernel. Debian/GNU Linux is a GNU operating system using the Linux kernel.
can u tell me whether linux kernel is written in
"c" or in "assembly level language".
Most of it is written in C, as that is much easier to program in than
assembly. However, assembly might be used in some areas whenever the
programmer needs more intimate access to the hardware than C might provide.
I have also read that cpu
understands only machine level language if so then how "c" and
"assembly level language" is converted in to machine level language.
Assembly is just a step above machine level language; any competent
programmer could convert assembly to machine code. However, that's
tedious and error prone, so programmers throughout the years have
written translation programs, called assemblers, that do the work for them.
For example, an assembly instruction to add the decimal numbers 19
(which is 13 in hex) and 43 (which is 2b in hex) (Kcalc has a mode that
will help you convert hex numbers to decimal and/or binary and
vice-versa) might be
add 13,2B
The programmer would look up the corresponding hex code for "add"; this
code will be different depending on what CPU is being used (a Pentium,
or a Sparc, or a PowerPC chip, etc), and the code chart is available in
books, online, from publications by the CPU manufacturer, etc.
Let's pretend the hex code for "add" in our little example is A9. So,
the above command in pure hex would be
A9 13 2B
Then that converts into binary quite easily. You can see a decimal to
hex to binary chart at the bottom of this page:
http://www.computerhope.com/binhex.htm
So to convert our hex instruction to binary, we convert each digit, such
that A becomes 1010, and 9 becomes 1001, etc. The converted instruction
looks like
1010 1001 0001 0011 0010 1011
This machine code essentially means that of the 24
transistors/capacitors/switches/magnetic dots on a tape/burned
depressions in a CD/etc needed to store that info, the first switch/mag
dot/etc is on, the next is off, the next is on, the next is off, then
on, off, off, on, off, off, off, on, etc.
The CPU understands switches being on and off, so it can understand this
code.
Look at the light switch on the wall of the room you're in. Just a
simple switch; it can be on or off. Now imagine a group of four of those
next to each other. This is equivalent to a "nybble". Now imagine a
second set of four next to the first set of four. Now you have eight
switches. Eight switches, or two nybbles, make a byte. You're familiar
with the term byte; you may have 128 Mega_bytes_ of RAM in your
computer. 128 MB of RAM is roughly 128 million groups of eight switches.
Unlike English, which can have words of four letters or 5 or 2 or 9 or
whatever, "words" (for the purposes of this conversation) in computer
language are usually always 8 "letters" long; thus the "byte" (there's
nothing particularly "magic" about this length; it's just what
programmers agreed on throughout the years). And as each letter can only
be on or off, just two states, rather than the couple of hundred or so
characters used in English (26 letters, upper and lower case, plus
punctuation and number symbols, etc), the language is referred to as
"binary".
So, if you had 6 sets of four light switches on your wall (and it'd be
easier to "read" them if they were grouped as three sets of two sets of
four, like so
1010 1001 0001 0011 0010 1011
which is the same as above, just spaced differently), then you could
program your lights with our instruction above. (Not that the lights
could understand this instruction, of course, but replace your lights
with the appropriate CPU and you've just instructed it to add two numbers.)
C code is considerably "higher". Whereas a programmer could
theoretically convert C to machine code, it would be much too difficult
and error prone to do for any practical purpose. Instead, conversion
programs called compilers have been written to do the translation work.
gcc is such a compiler.
To get a feel for how C code is converted into a language used by the
kernel, here's a simple little example:
http://www.faqs.org/docs/kernel/x145.html
along with the next page after it (click on "Next" at top or bottom of
that page)
You might want to read more of this book than just the two pages I
referenced; it might shed some light on the subject for you.
Also, searching the Internet (google is your friend) might get your more
and better information than going straight to the members of a mailing
list. There's lots of good info out there.
Hope this helps!
--
Kent
Reply to: