Thread: C programs into machine code

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    217

    C programs into machine code

    How do C compilers convert C source code into machine code? Does the C compiler convert its code into assembly language and then automatically find and use the assembler for that particular processor (the assembler which knows how to convert assembly into the instruction set of that particular processor).

    If so, how does the C compiler find the assembler? Is there a way I can find it on my computer? Or does the C compiler itself come shipped along with an assembler which supports various CPU architectures?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    The compiler + assembler + linker are usually bundled together as a complete toolchain.

    Compiler does foo.c -> foo.s
    Assembler does foo.s -> foo.o
    Linker does foo.o (and all other .o and .lib/.a files) -> foo.exe
    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
    Sep 2018
    Posts
    217
    But won't different processors have different instruction set? How does the assembler figure out what the instruction set of the processor is?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Assemblers are hard wired to their target processors.

    Sure, there may be a bunch of options for processor variants (-386, -486, -pentium etc).
    But if you're on an ARM machine, then you need an ARM based toolchain.


    Cross compiler - Wikipedia

    For your average desktop machine, the host machine and the target machine are one and the same.
    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.

  5. #5
    Registered User
    Join Date
    Sep 2018
    Posts
    217
    thanks salem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Convert assembly>machine code, machine code>assembly
    By wenxinleong in forum C Programming
    Replies: 12
    Last Post: 06-23-2011, 10:42 PM
  3. Programs Only Run on My Machine!
    By pobri19 in forum Windows Programming
    Replies: 20
    Last Post: 04-23-2009, 06:25 PM
  4. Replies: 4
    Last Post: 01-18-2008, 07:05 PM
  5. running old programs on new machine
    By task in forum Tech Board
    Replies: 1
    Last Post: 11-13-2002, 09:26 PM

Tags for this Thread