Choosing the Right Compiler for Your Microprocessor: A Newbie's Guide

  • Thread starter Thread starter RedX
  • Start date Start date
AI Thread Summary
Choosing the right compiler for a microprocessor involves understanding the relationship between the compiler, the operating system, and the chip architecture. Compilers are typically designed for specific chip architectures and may list OS compatibility instead of architecture due to the abstraction layers provided by modern operating systems. While many compilers can generate machine code for various architectures, they often rely on the OS API for resource access. The x86 architecture is noted for its backward compatibility, allowing software to run across different versions of Windows. Ultimately, understanding these distinctions helps in selecting a suitable compiler without needing to recompile for every processor.
RedX
Messages
963
Reaction score
3
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?
 
Technology news on Phys.org
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).
 
RedX said:
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?

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.

RedX said:
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.

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.

RedX said:
I have a Pentium, but that means I could have any operating system written for a Pentium.

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

RedX said:
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?

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.
 
schip666! said:
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.

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.

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".

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.
 
RedX said:
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.
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.
 
RedX said:
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.

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.

RedX said:
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.

There is an assembly language for any processor architecture. For instance, http://en.wikipedia.org/wiki/ARB_(GPU_assembly_language)" . 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" (CIL).

All part of the ubiquitous strive towards higher and higher level of hardware abstraction.
 
Last edited by a moderator:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top