Executable file

Thread Starter

gogo00

Joined Oct 28, 2023
43
Could someone help me to understand process of how an executable file is generated from multiple text files of a C program, I understand it's a broad topic, but I'm specifically interested in grasping a few key steps involved in the execution process. especially focusing on the assembler and linker stages?
I think Assembler converts c codes into the actual machine instructions that the CPU can execute directly.
 

WBahn

Joined Mar 31, 2012
32,883
The term "assembler" is generally reserved for a piece of software that converts "assembly code" into machine code. The compiler, at least conceptually and usually in reality, converts code from a high-level language, like C, to assembly code, then the assembler takes it from there.

Linking is a separate process in which references to things in different files (or in runtime libraries) are resolved.
 

Thread Starter

gogo00

Joined Oct 28, 2023
43
From what I've learned through internet research, when a compiler processes a C program into an executable file, it undergoes several operations, generating various files like assembly files, object files, and executables. In larger C projects, there can be multiple source (.c) files and header files (.h). During the initial phase, the preprocessor in the compiler includes all header files and replaces values with defined names. In the second phase, the compiler translates all source files into assembly files, then the assembler converts these into object files. Finally, in the third phase, the linker assigns addresses to all variables. However, there might be nuances or additional aspects to this process that I might not have covered.
 

MrChips

Joined Oct 2, 2009
34,829
From what I've learned through internet research, when a compiler processes a C program into an executable file, it undergoes several operations, generating various files like assembly files, object files, and executables. In larger C projects, there can be multiple source (.c) files and header files (.h). During the initial phase, the preprocessor in the compiler includes all header files and replaces values with defined names. In the second phase, the compiler translates all source files into assembly files, then the assembler converts these into object files. Finally, in the third phase, the linker assigns addresses to all variables. However, there might be nuances or additional aspects to this process that I might not have covered.
Some and all of the above. So what is your question again?
 

BobTPH

Joined Jun 5, 2013
11,528
the second phase, the compiler translates all source files into assembly files, then the assembler converts these into object files
Most compilers do not work that way, they go directly from the C to one or more internal forms, then to an object file without using a separate assembler.
 
Top