How does a program compiled for machine language run on different machines?

At school, we were taught that compilers compile a computer program for machine language. We were also taught that machine language consists of direct indications of hardware. Then how can the same compiled program run on several computer configurations with different equipment?

+5
source share
3 answers

Depends on what you mean by “other hardware”, if it is the same processor (or the same family, for example Intel x86), then the machine code instructions are the same.

- (, ..), , .

, ARM Intel x86, - - , ARM x86, , x86 funcs, , ARM.

: , hw - , ?

- , / . DOS BIOS interupt, BIOS, HW.

+11

, .

+4

I think it’s more accurate to say that native compilers are compiled into a specific set of processor instructions. Since there are families of processors that support backward compatibility: 8086 - 80386 - 80486 - 80586 - Dual Core - Quad Core ...; then each processor executes instructions of its ancestors. If you want to port the code to the processor architecture, then you definitely need a virtual machine or emulator, as mentioned earlier.

0
source

All Articles