Home  >  Article  >  What translation method is used to translate programs written in high-level languages ​​into machine language programs?

What translation method is used to translate programs written in high-level languages ​​into machine language programs?

青灯夜游
青灯夜游Original
2021-03-25 17:40:1156835browse

To translate a program written in a high-level language into a machine language program, two translation methods can be used: compilation and interpretation. The interpretation mode is to interpret and execute the source program sentence by sentence, that is, interpret one sentence and execute it. In the interpretation mode, no target file is generated. The compilation method is to first translate the entire source program into a machine language program, and then generate an executable program, usually resulting in a target program.

What translation method is used to translate programs written in high-level languages ​​into machine language programs?

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

To translate a program written in a high-level language into a machine language program, two translation methods can be used: compilation and interpretation.

  • The interpretation mode is to interpret and execute the source program sentence by sentence, that is, interpret one sentence and execute it, so no target file is generated in the interpretation mode. For example, the early BASIC language used the "interpretation" method.

  • The compilation method is to first translate the entire source program written in a high-level language into a machine language program, and then generate an executable program that can be run directly under the operating system, usually resulting in a target program.

The difference between compilation and interpretation

Compilation is to translate the source program into executable target code, and translation and execution are separate; Interpretation is a one-time translation and execution of the source program, without generating storable object code. This is just an appearance. The biggest difference between the two is: for interpretation and execution, the control when the program is running lies with the interpreter and not the user program; for compilation and execution, the control at runtime lies with the user program.

The interpretation has good dynamic characteristics and portability. For example, when the interpretation is executed, the type of variables can be dynamically changed, the program can be modified, and good debugging diagnostic information can be inserted into the program. The interpreter is transplanted to a different system, the program can run on the system with the transplanted interpreter without modification. At the same time, the interpreter also has great shortcomings, such as low execution efficiency and large space occupation, because not only space must be allocated to the user program, but the interpreter itself also occupies valuable system resources.

The compiler compiles each statement of the source program into machine language and saves it into a binary file. In this way, the computer can directly run the program in machine language at runtime, which is very fast;

The interpreter only interprets the program one by one into machine language for the computer to execute, so the running speed is not as fast as the compiled program.

More programming related For knowledge, please visit: programming video! !

The above is the detailed content of What translation method is used to translate programs written in high-level languages ​​into machine language programs?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn