EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: Kittu20 on July 27, 2023, 04:51:10 pm

Title: Process to Convert Human-Readable Code to an Executable File
Post by: Kittu20 on July 27, 2023, 04:51:10 pm
Hey  developers,

I'm eager to learn more about the following steps involved in this software development process: c language. I would be grateful if any of you could shed some light on what happens during these stages.

Editor: Initially, we write and manage the C code using a text editor or an integrated development environment (IDE).

Preprocessor: Before the actual compilation process begins, the preprocessor steps in to handle tasks like including header files, defining macros, and performing conditional compilation.

Compiler:

Assembler: Convert assembly code into machine code.

Linker: After the compilation of all necessary source files, the linker comes into action. It takes the generated object files, libraries, and other necessary dependencies and links them together to produce the final executable file.

Loader: Before the program can be executed, the loader loads the executable file into memory.

I'm interested in learning more details about each of these steps. What happens during compilation and assembly?


Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: PlainName on July 27, 2023, 07:05:11 pm
Is this homework? For some reason, you neglected to say previously.
Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: Kittu20 on July 27, 2023, 07:37:30 pm
Is this homework? For some reason, you neglected to say previously.
I want to clarify that this is not a homework assignment; rather, I'm seeking to understand some concepts better. Once I have a clear grasp on the topics, I would write and post to share my insights and get any necessary clarifications.

Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: DiTBho on July 27, 2023, 09:56:47 pm
I want to clarify that

you ask a question whose answer implies that you start to get a complete course in computer science from the elementary bases




Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: PlainName on July 27, 2023, 10:55:08 pm
OK, well....

Editor: you write the C code in plain text in whatever editor take your fancy. For instance:

Code: [Select]
#define   MESSAGE   "Hello world"

int
main(int argc, char **argv)
{
    printf("%s", MESSAGE);
    return 0;
}

Preprocessor: takes your code and does various things to it. Prepocessor commands generally start with '#', and in the example above the command is to define the string MESSAGE to mean "Hello world". The preprocessor just replaces MESSAGE, wherever it occurs, with "Hello world". The result is for printf, which outputs text to the console, to send "Hello world" rather than MESSAGE.
Note that the preprocessor is generally part of the compiler so unless you specifically ask for it you wouldn't see the processed output before the compiler gets it.

Compiler: takes the code (after preprocessing) and translates the statements into processor op-codes. For example, the code "var = 52" might translate to "mov a, 0x34". The latter would be fed through an assembler to create the binary code for the processor to execute. Some compilers may skip the assembler step and go straight from C code to binary data.

Assembler: converts the assembler output from the compiler into binary data the processor can run. In the above case, the assembler "mov a, 0x34" may resolve to "23 34" where '23' means 'mov a' (that is, move some value into the a register) and '34' is the value to use.

Linker: The output from the assembler needs to be placed into specific parts of the processor memory map, which is what the linker does. Having set the memory address of various things, the code that references those things needs to be updated to use the actual address, and this is also what the linker does.

Loader: This is a bit too broad. Basically you need to get the program, which your code defined and the compiler compiled and the linker linked, in the real memory of your processor, and this is what the loader does. Depending on the target it may be some file on external storage that is read into memory when required (which I think is your desired definition). If the program is already in memory (say, programmed into flash) then the loader may mean the part of code that copies various data into RAM.
Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: rhb on July 28, 2023, 04:27:19 am
May I suggest any of the many books on the subject?

Seriously, you are asking for an answer that has no bounds.  I've got probably 10 ft of books in my library on the topics you mentioned, which are only a small part of it.

You don't even mention formal grammars and parsing.  Stuff like optimization is very complex and changes constantly.  In the early '90s the performance killer was  branch delays until speculative execution and branch prediction were introduced a few years later and all the HPC rules changed yet again.

Reg
Title: Re: Process to Convert Human-Readable Code to an Executable File
Post by: DiTBho on July 28, 2023, 09:24:55 am
Seriously, you are asking for an answer that has no bounds

so, the answer is:
#42

(  ;D )