What is the difference between compilation and interpretation _ other integrated

Source: Internet
Author: User

What is the difference between compilation and interpretation?

The compiler compiles every statement of the source program into machine language and saves it as a binary file, so that the computer can run the program directly in machine language, which is very fast.

And the interpreter is only in the execution of the program, only a piece of interpretation into machine language to the computer to perform, so the speed is not as fast as the compiled program running.

This is because the computer can not directly recognize and execute the statements we write, it can only recognize the machine language (is the form of binary)

Low-level language and advanced language

The original computer program is expressed in the sequence of 0 and 1, the programmer is directly using machine instructions, without translation, from the paper tape hole input can be performed to obtain results. Later, in order to facilitate memory, will be used in the 0, 1 sequence of machine instructions are signed to help remember, these and machine instructions one by one corresponding mnemonics to become assembly instructions, thus the birth of assembly language. Both machine instructions and assembly instructions are machine-oriented, collectively referred to as low-level languages. Because it is a mnemonic for machine instructions for a particular machine, assembly language cannot be independent of the machine (a particular CPU architecture). But assembly language is also to be translated into machine instructions to execute, so there will be running on one machine assembly language translated into machine instructions running on another machine, that is, cross assembly technology.

Advanced language is a computer language from the perspective of human logical thinking, the degree of abstraction is greatly improved, it needs to be compiled into the target code on a specific machine to execute, a high-level language statement often requires several machine instructions to complete. High-level languages are independent of machine features by compilers that generate different target codes (or machine instructions) for different machines. So, specifically, to what extent will the high-level language be compiled, this is also related to the compiled technology, which can be compiled into a direct executable object code, or can be compiled into a middle representation, and then to the different machines and systems to execute, which often need to support the environment, such as the interpreter or virtual machine support, Java programs are compiled into bytecode, and then executed by virtual machines on different platforms is a good example. Therefore, the high-level language does not depend on the machine, refers to the different machines or platforms in the high-level language of the program itself unchanged, and the compiler to compile the object code to adapt to different machines. In this sense, through the cross assembly, some assembler can also get the portability between different machines, but this approach to the transplant is far less convenient and more practical than the advanced language.

Ii. Compilation and interpretation

The compilation is to translate the source program into executable object code, the translation and execution are separate, and the interpretation is to complete the translation and execution of the source program, and not to generate the stored target code. This is just a symptom, the biggest difference behind the two is that for interpretation execution, the control of the program runtime is in the interpreter instead of the user program; For compilation execution, the control of the runtime is in the user program.

Interpretation has good dynamic characteristics and portability, for example, when interpreting execution can dynamically change the type of variable, modify the program and insert good debugging diagnostic information into the program, and then migrate the interpreter to a different system, the program can run on a system that is ported to the interpreter without modification. At the same time, the interpreter also has a great disadvantage, such as inefficient execution, occupy a large space, because not only to the user program allocation space, the interpreter itself occupies valuable system resources.

The compiler compiles every statement of the source program into machine language and saves it as a binary file, so that the computer can run the program directly in machine language, which is very fast.
And the interpreter is only in the execution of the program, only a piece of interpretation into machine language to the computer to perform, so the speed is not as fast as the compiled program running.

    • edit: to form the source program (. ASM) using the editing software (EDIT.EXE or Notepad), such as: lx.asm;
    • Compilation : The source program is compiled using an assembler (MASM.EXE) to form the target file (. OBJ), in the following format: MASM LX. ASM;
    • Connection : connects the target program with the connector (LINK.EXE) to form an executable file (. EXE), in the following format: Link LX. OBJ;
    • execution: If the results are displayed on the screen, execute the executable file directly.
    • Debugging : Debug an executable file with the debugger (DEBUG.EXE) in the following format: Debug LX. Exe

1. To implement a language on a specific computer, the first thing to determine is a virtual computer that represents the semantic interpretation of the language, and a key question is whether the basic representation of the program execution is the machine language on the actual computer or the machine language of the virtual machine. This problem determines the realization of language. According to the answer to this question, the programming language can be divided into two main categories: the compiled language and the explanatory language.

2. The source program written by the compiled language needs to be compiled, compiled and linked to output the target code, then the machine executes the target code, obtains the running result, the target code is composed of the machine instruction, generally cannot run independently, because the source program may use some assembler program cannot explain the reference library function, and the library function code is not in the source program, at this time also need to link the program to complete the external reference and target module calls linked tasks, and finally output executable code. C, C + +, Fortran, Pascal, Ada are compiled to achieve.

3. In the interpretation language implementation, the translator does not produce the target machine code, but produces the intermediate code that is easy to execute, this kind of intermediate code is different from the machine code, the intermediate code explanation is the software support, cannot use the hardware directly, the software interpreter usually causes the execution efficiency to be low. A program written in an interpreted language is executed by another interpreter that understands the intermediate code. Unlike the compiler, the task of the interpreter is to interpret the source program's statements into executable machine instructions one at a time, without having to translate the source program into the target code and then execute it. For an interpreted basic language, a specialized interpreter is required to interpret the execution of basic programs, and each language is translated only in execution. This interpretive language is translated once every time, and thus inefficient.

4. Java is very special, Java programs also need to compile, but not directly compiled as a machine language, but rather compiled called bytecode, and then on the Java Virtual machine in the interpretation of the execution of bytecode. Python also uses a Java-like compilation model, which compiles python code into Python bytecode, and then a dedicated Python bytecode interpreter interprets the execution bytecode.

(Java Virtual machine Execution of bytecode is equivalent to simulating a CPU, and ruby1.8--is not before the virtual machine appears--is done by interpreting it as a syntax tree.) )

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.