Thread: Compilers.. assemblers.. linkers..

  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163

    Exclamation Compilers.. assemblers.. linkers..

    Can anyone point me at some documents on things like: (How does a compiler/assembler)
    - ... translates source to machine code?
    - ... creates various executable formats and object files?
    - How do you make a compiler/assembler? (extreme tabu I've noticed)

    I really want to know these things because it sounds interesting, so I please you to link me to every document on this thematic you know.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://www.bloodshed.net/compilers/index.html
    Should keep you busy for a while...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Thank you.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I very much doubt that it's Tabu to talk about compilers and compiler technology. It is very complicated, and my guess would be that there are less than 10 people who are active in the next week on this forum that has actually worked in the source code of a REAL "industrial quality" compiler (most likely candidate here is gcc).

    On top of that, there's usually little NEED to write your own compiler, assembler or linker, as there is almost always a compiler available that you can get for free - commonly gcc (it supports several different processor architectures, C, C++, Java, Fortran and some other less common languages).

    This is FAR more than can be covered even in 100 posts, never mind one.

    The frist step is to parse the code into some internal representation of the symbols, e.g:
    Code:
    // inside a functiokn of some sort.
    int x;
    x = 2;
    would be translated to
    Code:
    variable: name="x", type "auto", location="stack";
    assignment: target=variable("x"), source = constant(int, 2);
    The compiler will then do take the complete list of such internal representation and produce the machine-code from that. Of course, it's quite likely that there will be one or more other intermediate steps, and for "industrial quality", a good optimizer will be necessary to produce good quality code (look at the differences between gcc with -O0 and -O1, -O2 and -O3).

    Writing an assembler is a whole lot easier (at least if you only have one processor architecture to worry about - gas which supports a few dozen different processor types is quite complex, because everything needs to be able to cope with lots of different options). It's essentially just two parts:
    1. Translate op-code into machine code.
    2. Deal with symbols (labels, external symbols, exported symbols and some trivial math).

    A linker is not very difficult either, from a generic perspective. It's basicly just dealing with symbols and resolving external symbols in one module by finding the corresponding symbol in a different module.


    If you go to a university that has a computer oriented program (e.g. Computer Science or Software Engineering), there will probably be some compiler oriented course in the corriculum - it may not be part of any particular program, but rather an optional course, but I'm pretty sure you will find one.

    One of the more commonly recomended books on the subject is:
    http://en.wikipedia.org/wiki/Princip...ompiler_Design

    However, there are several others, including free ones.

    However, going from the level of "being able to write a simple compiler" to producing "industrial quality" is a huge difference. A small, simple compiler is probably in the order of a few tens of thousands of lines of code. A industrial strength compiler will be several hundred thousand lines of code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Yes, I know some of things you said. I wouldn't build my own compiler/assembler so I can use it, I would build it to understand how it works. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. books with compilers
    By alyeska in forum C++ Programming
    Replies: 3
    Last Post: 12-11-2006, 03:30 PM
  2. C++ Builder Comparison
    By ryanlcs in forum Tech Board
    Replies: 14
    Last Post: 08-20-2006, 09:56 AM
  3. Is It Possible To Install Multiple Compilers?
    By mishna_toreh in forum C Programming
    Replies: 3
    Last Post: 05-13-2005, 07:32 AM
  4. Compilers for Windows
    By LegendsEnd in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2004, 08:03 AM
  5. Compilers, Compilers, Compilers
    By Stan100 in forum C++ Programming
    Replies: 11
    Last Post: 11-08-2002, 04:21 PM

Tags for this Thread