Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Newbie question on compilers

  1. Jul 4, 2010 #1
    A compiler converts a high-level language to machine code. So when you buy or download a compiler, don't you have to make sure the compiler is compatible with your microprocessor? Yet when I look at the various compilers I can download, the requirements are listed as what operating system you are running, and not your chip architecture.

    I have a Pentium, but that means I could have any operating system written for a Pentium. The operating system does not determine the chip architecture (indeed it is written for the chip architecture), so how can the requirements for a compiler be the operating system and not the chip architecture?
  2. jcsd
  3. Jul 4, 2010 #2
    Compilers are usually made for a specific chip architecture running under a specific operating system, where those two may be conflated (like Windows) or the details relaxed vis the actual versions or such. However it doesn't have to be the case. The compiler translates high-level instructions to something lower. That lower-level might be some kind of portable object code which would then be translated into instructions for a specific chip by an "assembler". The OS dependence is more in the area of support libraries -- how one accesses resources through the operating system. As long as one has a good API specification, e.g. Posix -- I'm not calling it good...just sufficient -- you can "link" your portable object code with the correct libraries and not have to know exactly what is under the sheets. This is the essence of "cross-compiling".

    Of course you have to run all of these programs somewhere, so they themselves have to be built for some specific hardware/OS version(s).
  4. Jul 4, 2010 #3
    Nope. Most everyone and their grandma have a pc with an x86 or compatible instruction set architecture processor. With various revisions and extensions over the years it's still pretty backwards compatible.

    For other stuff there's the hardware abstraction layer.

    You really needn't concern yourself with things the compiler developers didn't want you to. The OS matters. Because the OS API is about as low as you need to be privy to nowadays for all but the most advanced software.

    With Java, not even the OS matters as much. It only matters in as much as whether there's a version of the JRE written for it.

    That would defeat the purpose of an operating system and of open ISAs, to need a compiler and to recompile for every processor out there. Plus the tendency is ever towards more abstraction. Interpreted languages, just in time compilation, common intermediate language, bla bla.

    It's all good.

    No. You have an OS written for an instruction set.

    Not so. You can't readily run MacOSX on x86 processors. You need virtualization.
    And you can't readily run Windows on PowerPC processors. You need virtualization.
  5. Jul 4, 2010 #4
    I sometimes see compilers advertised as written for 32-bit Windows. Are they assuming the x86-32 architecture? I was thinking that it could be the case that 32-bit Windows was only written for the x86-32 architecture, so when you specify 32-bit Windows you automatically specify x86-32, but I don't know if that's true or not. I know for 64-bit Windows there is the x86-64 architecture, and also an Itanium architecture, so a 64-bit Windows compiler would have to specify whether it is x86-64 or Itanium.

    Can all the different type of chips read Assembly, i.e., convert Assembly code to their machine code? If so, then all compilers could just translate into Assembly, which could then be converted to your particular machine code for your particular processor.
  6. Jul 4, 2010 #5


    Staff: Mentor

    I'm not aware that any chips can "read" assembly. Assembly code is human-readable code that corresponds to machine code for a particular processor. Each processor architecture (e.g. x86-32, x64, Itanium, and so on) has its own instruction set and hence its own kind of assembly code.

    Chips are generally not capable of converting (or translating) assembly code into machine code. For that you need an assembler, a software tool that translates assembly code into machine code.

    Some compilers, which are called cross-compilers, are capable of generating machine code for a number of different processor architectures. So for example, you could develop a program on a Windows machine, and have the compiler produce machine code that would run on, for example, a Motorola 68000-family processor.
  7. Jul 4, 2010 #6
    The x86 architecture is designed towards backwards compatibility. I have an x86-64 processor but run windows XP HE on it. That's why I can't run applications compiled for windows on the x86-64 ISA.

    But I could if I had XP 64bit ed. The CPU would just switch between 32 and 64 bit modes or use 64 bit registers to hold 32 bits of data. Etc.

    There is an assembly language for any processor architecture. For instance, http://en.wikipedia.org/wiki/ARB_(GPU_assembly_language)" [Broken]. This language is just a shade above the level of actual machine instructions. Or executable code.

    What you're thinking of there is http://en.wikipedia.org/wiki/Interpreted_language" [Broken] (CIL).

    All part of the ubiquitous strive towards higher and higher level of hardware abstraction.
    Last edited by a moderator: May 4, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook