Talk in detail about the transition process from program to executable program

Program to executable program

  In a computer, the computer divides 8 consecutive bits into a small group. This small group forms a byte. Because each bit can represent two states of 0 and 1, so a bit can also represent a total of 2 ^8 states , which are 0-255 , and then ASCII is used.
  For all languages, all of the codes we touch are hello printing, where every character in it can be found and expressed in ASCLL.
  Let's take hello as an example to describe the process of programming to the machine's binary system. As shown in the figure:
Insert picture description here
  1. For the preprocessing stage , the computer mainly expands the header files that people often say. The header files here include header files that reference others and their own custom header files, and the header files inside cannot appear Containment relationship, but if there is a containment relationship, it can be resolved, but I won't describe it too much here. After this we will get another C language program usually with the suffix .i.
  2. The compilation stage is mainly to translate .i files into .s files, which contains something called assembly language program. Assembly language is often used in life. A qualified programmer is not required to be able to write Assembly language, but at least you can understand assembly.
  3. In the assembly stage , the assembler will translate the .s file into machine instruction statements. Its byte encoding is machine language instructions instead of characters. If we open the hello.o file in a text compiler, what we see is a bunch of Garbled.
  4. Link phaseAt this stage, the computer will call the function used. For hello, the file printf.o will be called here, because this file is also a library file written by someone, and it is also a function. At this stage, The separately compiled printf.o file will be integrated into the hello.o file in some way. When all the files that need to be integrated are integrated on the hello.o file, the hello.o file becomes an executable object file , Then it can be loaded into memory and executed by the system.

Guess you like

Origin blog.csdn.net/weixin_43580319/article/details/111308095