LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 04-05-2006, 10:44 PM   #1
ty13
Member
 
Registered: Apr 2006
Location: US
Distribution: Debian. Ubuntu
Posts: 35

Rep: Reputation: 15
General OS question, newb question


What is and OS written in, what kind of code, and what are the GUI installers written in? Is it the same? Sorry for sounding so stupid, but it would be great if someone could help me out here.
 
Old 04-05-2006, 10:58 PM   #2
xpromisex
Member
 
Registered: Apr 2004
Location: Statesboro, GA
Distribution: Arch Linux 2007.05 "Duke" (Kernel 2.6.21)
Posts: 447

Rep: Reputation: 30
Operating systems tend to be written in assembly (or in a higher level language and "translated down" from there.) Some of the HobbyOS's let you know. (I think Minuet is written fully in Assembly) I'm not exactly sure what the installers are written in, but I assume that it is much the same as the OS. Maybe Assembly with additional Libraries? Now I want to know too.
 
Old 04-05-2006, 11:01 PM   #3
ty13
Member
 
Registered: Apr 2006
Location: US
Distribution: Debian. Ubuntu
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks dude, now I am gonna go find out what assembly is, heha.
 
Old 04-05-2006, 11:20 PM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Mostly a combination of Assembly and C (the Linux kernel, in fact, was written mostly in C).
 
Old 04-06-2006, 04:02 AM   #5
baldy3105
Member
 
Registered: Jan 2003
Location: Cambridgeshire, UK
Distribution: Mint (Desktop), Debian (Server)
Posts: 891

Rep: Reputation: 184Reputation: 184
That will be assembler, or assembly language or possibly machine code. Not assembly, please, thats what you do at school in the "big hall"
 
Old 04-06-2006, 06:48 AM   #6
ty13
Member
 
Registered: Apr 2006
Location: US
Distribution: Debian. Ubuntu
Posts: 35

Original Poster
Rep: Reputation: 15
The kernel is written in C? Wait, so, the computer, I mean, the hardware, can interpret C? Or there an interpreter to directly turn it to binary or, assembly? hmmmm...... this shows how stupid I am concerning this stuff...
 
Old 04-06-2006, 09:00 AM   #7
baldy3105
Member
 
Registered: Jan 2003
Location: Cambridgeshire, UK
Distribution: Mint (Desktop), Debian (Server)
Posts: 891

Rep: Reputation: 184Reputation: 184
You write code directly in Assembler, Assembler is converted directly to binary which is the only thing the CPU understands. Each assembler command has a direct binary equivalent, so you are spelling the program out step by step.

When you write in C or Pascal etc you are writing higher level commands which do not have direct machine code equivalents. This code must be interpreted into assembler and one C statement often represents huge chunks of assembler.

So in assembler to add two numbers you would need to say , move data from memory location X to register A, move data from memory location Y to B, add A to B, move result from A to memory location Z.

In C you say variableA + variableB. The command is read by the compiler which then substitutes the chunk of assembler in the binary.

You might think of source code not as a program in its own right but as a set of instructions which tell the compiler how to put together the chunks of predefined machine code into a binary that you will actualy run.
 
Old 04-06-2006, 09:05 AM   #8
Dragineez
Member
 
Registered: Oct 2005
Location: Annapolis
Distribution: Ubuntu
Posts: 278

Rep: Reputation: 41
Chicken And The Egg

Which prompts the question, what is a compiler written in? I love the sense of humor of *nix programmers. One of my favorite command names is "yacc" or "yet another compiler compiler".
 
Old 04-06-2006, 09:33 AM   #9
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
A compiler is written with the compiler. Sounds recursive and in a sense all inter-related. The development of this generation of compilers are by using high-level languages, particularly C. Most high-level language compilers are also written using C and assembly (mostly).

I think the original compiler ever written was using a combination of machine code and assembly code.

If you want to really get deeper into this I suggest reading Linkers and Loaders. Great book, goes into the theory of compilers, libraries, linkers and loaders and such stuff.

Another useful link:
http://cs.wwc.edu/~aabyan/464/Book/

However, writing a compiler is a complex thing. Maybe there are less than 100 programmers in the world who write compilers.

Last edited by vharishankar; 04-06-2006 at 09:40 AM.
 
Old 04-06-2006, 07:19 PM   #10
peter_89
Member
 
Registered: Jan 2006
Distribution: Microsoft Windows XP Professional SP2; Slackware Linux 10.2
Posts: 215

Rep: Reputation: 30
Quote:
Operating systems tend to be written in assembly
Just a note, nobody (with around one or two exceptions) writes operating system entirely in assembly anymore. It is very efficient, but you end up spending far too much time making the whole thing work and in the end all that time spent is not worth the extra efficiency. The standard for operating systems these days is C/C++. However, commonly accessed bits and pieces (the boot loader being a good example) are written in assembly. It is possible to have a mix. As for writing compilers? Those are written entirely in assembly to compile as quickly as possible (and because C/C++ wouldn't be able to get down to actually manually manipulating bits the way a compiler would need to).
 
Old 04-06-2006, 11:16 PM   #11
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 32
Quote:
Originally Posted by Harishankar
However, writing a compiler is a complex thing. Maybe there are less than 100 programmers in the world who write compilers.
That's an insanely low estimate. Just look at the number of free and commercial compilers out there for various languages. You could probably find more than 100 different compilers without too much trouble, and I'm sure many of them have more than one developer. In fact, I suspect Microsoft alone employs more than 100 people to work on its various compilers. Yeah, compiler building is hard, but it's not that hard.
 
Old 04-07-2006, 10:32 AM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,636
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Actually, compiler construction is taught at every University and even some advanced trade-schools. Although the programs are intricate, the topic has been discussed ad nauseum and very powerful tools exist to get you over the "rough spots."

It might well be said that while the compilers do an intricate job, they are not, themselves, terribly intricate programs. (Detailed, yes. Intricate, no.) And one of the objectives of the tool-sets is, specifically, to enable that to be the case. One of the "tricks" that is used extensively is the notion of, well, "reading a map." You can navigate anywhere if you know how to read a map and follow it. The procedure of "reading a map and following it" is fairly easy to explain/program, and it remains fairly simple whether the map being followed is simple or complex. So compilers make a lot of use of "maps" (grammars).

As to the background of all these topics ...

(1) The computer (CPU) executes binary code, typically consisting of millions and millions of instructions. (Some languages use what is called "p-code," where the "instructions" basically correspond to short subroutine-calls.)

(2) Compilers are normally used to generate all those instructions. A compiler is a program that takes source-code as input and produces (on a good day...) instructions as output. The language is designed to be practical for people to use, and a single statement might generate dozens or hundreds of CPU instructions. For this reason they're called "high-level" languages.

(3) At the opposite extreme, "assemblers" process a language in which there is a very close, nearly one-to-one correspondence between the statements in the language and the instructions recognized by the CPU. Although stand-alone assemblers exist and are used, languages such as C and C++ include a built-in assembler and support the insertion of assembler-code sequences (intermixed with C/C++ code).

(4) Compilers aren't built "from scratch" any more, because there's just no need to do it (again). Long ago, someone bootstrapped a small, hand-written mini-compiler that supported exactly enough language to allow the mini-compiler to be written in itself .. to compile itself. Once that was done, additions to the compiler could be made in the language itself, expanding the mini-compiler until it was a complete compiler.

(4a) These days, when someone invents a new CPU chip or version of a chip, programmers use cross-compilers. These are compilers that generate instruction-files intended for a type of CPU different from the one on which the compiler is running. The binary file is then uploaded to the new machine. A native, optimized compiler can be prepared for the new architecture in a matter of days.
 
Old 04-07-2006, 04:32 PM   #13
ty13
Member
 
Registered: Apr 2006
Location: US
Distribution: Debian. Ubuntu
Posts: 35

Original Poster
Rep: Reputation: 15
Thank you guys for all the info, it is greatly appreciated
 
Old 04-07-2006, 07:44 PM   #14
peter_89
Member
 
Registered: Jan 2006
Distribution: Microsoft Windows XP Professional SP2; Slackware Linux 10.2
Posts: 215

Rep: Reputation: 30
Quote:
Originally Posted by AdaHacker
Yeah, compiler building is hard, but it's not that hard.
Writing a compiler = Not that hard
Writing a good compiler = Unimaginably hard
 
Old 04-11-2006, 08:21 PM   #15
aldimeneira
Member
 
Registered: Jun 2005
Distribution: Ubuntu
Posts: 132

Rep: Reputation: 15
Since the first Unix implementation, OS code is mostly C/C++

Qt(KDE) uses C++
GTK(GNOME) uses C
NeXT OS and Mac OS X uses Objective C (C++ variant)

Writting an OS in assembler is deprecated and IMO insane. Maybe for some specific parts to enhance performance (ie: the boot loader).

Last edited by aldimeneira; 04-11-2006 at 08:23 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newb question sicness Slackware 4 11-09-2005 03:40 AM
this is a general way newb question... simple Linux - Newbie 4 05-30-2005 12:54 PM
Very newb question m2azer Linux - Newbie 3 09-19-2004 06:58 PM
A Newb Question pt. 2 gnr2k3 Linux - Newbie 3 08-30-2003 05:37 PM
A Newb Question gnr2k3 Linux - Newbie 1 08-30-2003 04:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration