Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the C++ compiler know which CPU architecture is being used

Tags:

c++

assembly

with reference to : http://www.cplusplus.com/articles/2v07M4Gy/

During the compilation phase,

This phase translates the program into a low level assembly level code. The compiler takes the preprocessed file ( without any directives) and generates an object file containing assembly level code. Now, the object file created is in the binary form. In the object file created, each line describes one low level machine level instruction.

Now, if I am correct then different CPU architectures works on different assembly languages/syntax.

My question is how does the compiler comes to know to which assembly language syntax the source code has to be changed? In other words, how does the C++ compiler know which CPU architecture is there in the machine it is working on ?

Is there any mapping used by assembler w.r.t the CPU architecture for generating assembly code for different CPU architectures?

N.S : I am beginner !!

like image 676
user7689322 Avatar asked Dec 07 '22 19:12

user7689322


1 Answers

Each compiler needs to be "ported" to the given system. For each system supported, a "compiler port" needs to be programmed by someone who knows the system in-depth.

like image 144
Lundin Avatar answered Apr 09 '23 00:04

Lundin