What is the difference between compilation and interpretation?

Source: Internet
Author: User

CompilerIt is to compile every statement of the source program into a machine language and save it as a binary file. In this way, the computer can run the program directly in the machine language at a high speed;

WhileInterpreterThe execution speed is not as fast as the compiled program.

This is because computers cannot directly understand and execute the statements we write. They can only recognize machine languages (in binary format)

 

I. Low-Level and advanced languages

The original computer programs are expressed in a sequence of 0 and 1. Programmers directly use machine commands without translation. The results can be obtained by inputting punched paper tapes. Later, in order to facilitate memory, machine commands expressed in series 0 and 1 were used with symbolic mnemonic. These mnemonic symbols that correspond to machine commands one by one became Assembly commands, which gave birth to the assembly language. Both machine commands and Assembly commands are machine-oriented, collectively referred to as low-level languages. Because it is a placeholder for machine commands on a specific machine, the assembly language cannot be independent from the machine (Specific CPU architecture. However, the assembly language can only be executed after being translated into machine commands, therefore, there are also ways to translate assembly languages running on one machine into machine commands running on another machine, that is, the cross assembly technology.

Advanced language is a computer language from the perspective of human logic thinking. The degree of abstraction is greatly improved. It must be compiled into the target code on a specific machine for execution, A statement in an advanced language usually requires several machine commands. The features of advanced languages independent of machines are achieved by the compiler generating different target code (or machine instructions) for different machines. Specifically, to what extent should we compile the advanced language? This is also related to the compilation technology, which can be compiled into a direct executable target code, it can also be compiled into an intermediate representation and executed on different machines and systems. In this case, it is usually necessary to support the environment, such as the support of the interpreter or virtual machine, and the Java program is compiled into bytecode, it is a good example to use virtual machines on different platforms. Therefore, advanced languages do not depend on machines. It means that programs in advanced languages on different machines or platforms remain unchanged, and the target Code Compiled by the compiler is used to adapt to different machines. In this sense, through cross-assembly, Some assembler programs can also achieve portability between different machines, but the portability obtained by this approach is far less convenient and practical than that of advanced languages.

Ii. Compilation and interpretation

Compiling translates a source program into executable target code, which is separated from execution. The explanation is to translate and execute the source program at one time without generating the stored target code. This is just a representation. The biggest difference between the two is that for interpretation execution, the control of the program running is in the interpreter rather than the user program; for compilation and execution, the runtime control is in the user program.

Interpretation has good dynamic characteristics and portability, such as dynamically changing the variable type during interpretation execution, modifying the program, and inserting good debugging and diagnosis information in the program, the interpreter is transplanted to different systems, and the program can run on the system where the interpreter is transplanted without modification. At the same time, the interpreter has many disadvantages, such as low execution efficiency and large space occupation, because it not only needs to allocate space to the user program, but also occupies valuable system resources.

The compiler compiles every statement in the source program into a machine language and saves it as a binary file. In this way, the computer can run the program directly in the machine language at a high speed;
The interpreter is interpreted as a machine language for execution only when the program is executed, so the running speed is not as fast as that of the compiled program.

1. Editing: Use the editing software (edit. EXE or notepad) to form a source program (. ASM), for example, lx. ASM;
2. Assembly: Compile the source program using an assembly program (MASM. EXE) to form the target file (. OBJ). The format is as follows: MASM lx. ASM;
3. Connection: connect the target program with a Connection Program (link. EXE) to form an executable file (. EXE) in the following format: link lx. OBJ;
4. Execution: if the result is displayed on the screen, execute the executable file directly.
5. debugging: debug the executable file with the debug program (Debug. EXE) in the following format: Debug lx. exe

1. to implement a language on a specific computer, you must first determine the virtual computer that represents the semantic interpretation of the language, A key issue is whether the machine language on the actual computer or the machine language of the virtual machine during program execution. This problem determines the implementation of the language. According to the answer to this question, the programming language can be divided into two categories: compiled language and interpreted language.

2. the source program compiled by the compiled language must be compiled, compiled, and linked to output the target code. Then, the machine executes the target code to obtain the running result. The target code consists of machine commands, generally, it cannot run independently, because the source program may use some assembler programs that cannot interpret referenced library functions, and the Library Function Code is not in the source program, in this case, you also need to link the program to complete the link task called by the external reference and target module, and finally output executable code. C, C ++, Fortran, Pascal, and Ada are all compiled and implemented.

3. in the implementation of interpreted language, the translator does not generate the code of the target machine, but generates intermediate code that is easy to execute. This intermediate code is different from the machine code, the explanation of intermediate code is supported by software, and hardware cannot be used directly. The software interpreter usually causes low execution efficiency. A program written in interpreted language is executed by another interpreter that can understand intermediate code. Different from compiling a program, the task of interpreting a program is to interpret the statements of the source program into executable machine commands one by one. You do not need to translate the source program into the target code before executing it. For an interpreted BASIC language, a dedicated interpreter is required to explain and execute the BASIC program. Each language is translated only when it is executed. This interpreted language translates every time it is executed, resulting in inefficiency.

4. Java is very special. Java programs also need to be compiled, but not directly compiled as the machine language. Instead, the compilation is called bytecode and then executed in the Java Virtual Machine in an interpreted way. Python also adopts a compilation mode similar to Java. First, the python program is compiled into a python bytecode, and then a special Python bytecode interpreter is responsible for interpreting and executing the bytecode.

(Java Virtual Machine's execution of bytecode is equivalent to simulating a CPU, while ruby1.8 -- before the VM has appeared -- it is executed by interpreting the idiom tree .)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.