Process to Convert Human-Readable Code to an Executable File - Page 1
Forum section: electronics / general

author: Kittu20
author_rank: Regular Contributor
timestamp: July 27, 2023, 04:51:10 pm
content: 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?

author: PlainName
author_rank: Super Contributor
timestamp: July 27, 2023, 07:05:11 pm
content: Is this homework? For some reason, you neglected to say previously.

author: Kittu20
author_rank: Regular Contributor
timestamp: July 27, 2023, 07:37:30 pm
content: Quote from: PlainName on July 27, 2023, 07:05:11 pmI 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.

author: DiTBho
author_rank: Super Contributor
timestamp: July 27, 2023, 09:56:47 pm
content: Quote from: Kittu20 on July 27, 2023, 07:37:30 pmyou ask a question whose answer implies that you start to get a complete course in computer science from the elementary bases

author: PlainName
author_rank: Super Contributor
timestamp: July 27, 2023, 10:55:08 pm
content: OK, well....Editor: you write the C code in plain text in whatever editor take your fancy. For instance:Code:#define MESSAGE "Hello world"intmain(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.

author: rhb
author_rank: Super Contributor
timestamp: July 28, 2023, 04:27:19 am
content: 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

author: DiTBho
author_rank: Super Contributor
timestamp: July 28, 2023, 09:24:55 am
content: Quote from: rhb on July 28, 2023, 04:27:19 amso, the answer is:#42()