Compilers

This is a discussion on Compilers within the Tech Board forums, part of the Community Boards category; Do most good compilers generate assembly code first or do they go directly to machine code?...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    266

    Compilers

    Do most good compilers generate assembly code first or do they go directly to machine code?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    A good compiler will do a correct translation between the source code and whatever target language it is built for. Depending on the programming language, what constitutes the build process and the target system of the compiler, a compiler may not even translate source code into assembly or machine code.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree with Mario's explanation, but I'd like to clarify:
    C and C++ compilers most often do not produce assembler code, but goes directly to the machine code in an object file. Most, however, have an option to produce assembler code instead of object 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.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    GCC is an important exception, in that nearly all backends go through assembly code and don't even have machine code emitters. GCC relies on the system assembler (GNU as on Linux) for generating machine code.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    I was asking this because I was really interested in programming language development and wanted to know whether to learn asm or machine code. Since it seems machine code might be a safer bet, any tutorials or good books to start with?
    P.S I tried google for tutorials but couldn't find any.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Asm and machine code are almost the same thing. One is with letters and numbers, the other is in binary or hex. Learn assembly first, because it's more accessible.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    For most compilers - machine code first. Outputting assembly code from machine code is relatively easy compared to assembling the assembly code into machine code.

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    >>Asm and machine code are almost the same thing. One is with letters and numbers, the other is in binary or hex. Learn assembly first, because it's more accessible.

    That seems a little unreasonable in my head. Why would you want to do that? This seems to me like a learn C before C++ kind've thing.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Because

    mov ax, bx

    is more readable than

    DF541231234324FDEABAA etc.

    And because there are tutorials for learning assembly, but the resources for learning machine code assume that you already know assembly.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    I'm not even sure if it makes sense to learn machine code if the hardware manufacturer provided an assembly language.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Most assemblers tell you the next values of the opcodes. Once you understand assembler a bit you will realize that machine code and assembler are quite interchangeable if you read the hex values of the opcodes. Unless you are writing something that needs to produce the machine code, however, I do not see why one would want to use it (I hate to even use the word learn because there isn't technically anything to learn.... Its more an issue of what values represent what opcode).

    Typically in programs that I have written that are capable of altering machine code I will use macros such as

    Example:
    Code:
    #define LDIV   (0x0138)
    #define LMUL  (0x013C)
    Thus eliminating the need to look at something nasty and in a binary form.

  12. #12
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    Is machine code more or less portable than asm? I would imagine asm is more portable among operating systems but machine code is more portable among hardware.

  13. #13
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Assembler is not portable at all. It just gives easy to read names to all the opcodes which are just hexidecimal values otherwise. It is nothing more, and nothing less. It would make little sense to not learn assembler. Once you know and understand assembler, you could theoretically write machine code. But to be honest, its hard to read machine code.

  14. #14
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    NASM is portable among operating systems isn't it?

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    Across operating systems, yes sure. But to an assembler there is no such thing as an operating system
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c compilers
    By kumarangopi in forum C Programming
    Replies: 2
    Last Post: 11-22-2006, 11:12 AM
  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, 07:03 AM
  5. Compilers, Compilers, Compilers
    By Stan100 in forum C++ Programming
    Replies: 11
    Last Post: 11-08-2002, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21