Essential internal power programming (on)

zhaozj2021-02-11  212

Essential internal power programming (on)

1. What is the program?

In short, the program is used to describe, guiding the computer to complete the task we need to complete (the generalized program also includes the relevant software to run the image, animation, sound and other resources). For example, I have to print a letter "a" to the screen; or let the CPU calculate the value of 2 3, and so on. Due to factors such as era, thinking, programming tasks, and personal preferences, there have been many description methods, and we distinguish these different descriptions, we call them different languages. For example, as mentioned earlier, you have to print a "A" character to the screen, and the corresponding description in the Basic language is:

Print "a"

The following is a description under Pascal:

Writeln ('a');

Give a C language again:

Printf ("a");

And C is more inclined to the following statements:

COUT << "a";

Here is Java:

System.out.print ("a");

The above, only one of the most basic implementations of the output "A" character can be seen that there is often a considerable difference between different languages. Of course, what we just "appreciated" is only the difference in form, and the differences behind it are the most important.

In addition, the programming language is also high and low-level points. Oh, don't expect the phrase "low" language implementation to think that the "low" language implementation is less than "advanced" language - the most "low" language can implement all functions, and those too "advanced" Language may have such a limit. It turns out that the high and low here is not a strong or not, but refer to the language description ability, or the approach of language and human natural language (way of thinking). In fact, the only computer that "understand" is the most "low" machine language, which is white, is a binary command code like 0101. However, it is too tired to write instructions in the day 0101, and it is very easy to make mistakes, so there is a compilation language relative to "advanced". Its and machine language can basically do one by one, but its writing is full. Similar The MOV, JMP helps, rather than a large 0101. Therefore, it is very convenient. When the assembly code is written, then the program that can be converted automatically to the executable binary code.

Although assembly language is very kind to machine language, it is very kind, but because it is largely, it is a simple corresponding replacement of machine language, so it is particularly cumbersome when writing some complex large programs; due to its expression ability It is too simple to avoid; in addition, due to the machine language corresponding to the assembly language, it can actually be regarded as a series of operations for hardware and systems, so once in different system platforms or machines, it is almost necessary To make changes or even rewritten. Even a simple operation like previously output "A", write two different assembly versions, respectively, in Windows and UNIX. In fact, the function we have requested is the same, but the abstraction of the assembly language is too low, so it reflects. To this end, people have developed a variety of advanced programming languages, like Fortran, Ada, Lisp, Basic, Pascal, C / C , and Java, C #, etc. in recent years. Since their abstraction is relatively high, the source code does not have to correspond to hardware, the system underlayer operation, so the transplantability is much better than compilation, and it is not necessary to change the source code for different system platforms or machines.

Since then, the program is divided into two categories, and a class called "source program" is the code that the programmer is easy to read with a variety of relatively high-level language, including the assembly code mentioned earlier, and others. All the code written in all advanced programming; the other class is called "executable program", which is the finalized binary after the assembly code or advanced language code passes the program's conversion, our computer can directly identify and execute it. So "executable". The corresponding concept, as well as "source code" / "executable code", "source file" / "executable file", etc. You must be easily understood, "Source Code" refers to the code written in a compilation or advanced language. These codes We save them in the form of files, become a source file. Most source files are stored in the simple text form, and there is no difference between our common .txt files, just to indicate that it is a source file, it usually does a different extension, like a Basic language. BAS, C language is .c and so on. Therefore, you can create or edit them with a simple text editor such as Notepad.

2. From source code to execution

As mentioned earlier, the computer only recognizes binary executable code, and we are more happy to use assembly language and various advanced languages. So, how do these source programs we have written ultimately?

For assembly languages, a program similar to the converter has been mentioned in front, which can write the assembly language we write into a machine language, and then save it in a program file it generated, it will be execute program.

The senior language family is very rich, so the solution to this problem is also the eight fairy pass the sea, each shows the gods. In general, no more than two categories: compilation and interpretation.

Let's take a look at the compilation type. In fact, it is the same as the previous assembly language: there is a program responsible for translation to convert our source code, generate the corresponding executable code. This process is professional, called Compile, and the program responsible for compiling is naturally called compiler. If we write program code is included in a source file, then it will generate an executable file directly after compiling, we can run directly. But for a more complex project, in order to facilitate management, we usually disperse code in various source files as different modules. At this time, you will generate the target file (Object File) instead of the executable of the previously mentioned. Generally, a source file is compiled with a target file. The content in these target files is basically an executable code, but because only a part of the entire project, we can't run directly. The compilation of all source files is very good, we can finalize these semi-finished target files "package" into an executable file, this work is done by another program, because this process seems to have the executable code The target file is connected to the assembly, so it is also known as a link (LINK), and the program responsible for the link is called ... Just call the Linker. In addition to the link target file, the link may have a variety of resources, icon files, sound files, but also responsible for removing redundant repetition code between target files, etc., so ... is also quite tired . After the link is completed, you can usually get the executable of what we want.

Above we probably introduce the characteristics of the compilation language, now look at the interpretation type. Hey, from the literal, "Compilation" and "Explanation" have indeed "translation" meaning, and the difference is that the timing of translation is not large. Bi-side: If you intend to read a foreign book, and you don't know this foreign language, then you can find a translation, give him enough time to let him translate the whole book from the end, then put the book Native language is given to you; or, you also immediately let this translation assist you to read, let him translate a sentence, if you want to look back in a chapter, he has to re-send you. In two ways, the former is equivalent to the compilation type we have just mentioned: convert all the code into machine language, then write an executable; and the latter is equivalent to the interpretation we have to say: before the program is running There is only an active program without executable; and each program executes an instruction to the source program, there will be a housing that is called the interpreter to convert the source code into a binary code for execution, in all words, It is constantly explaining, executing, explaining, executing ... so the interpretation program is inseparable from the interpretation. As early as early Basic is a classic interpreted language. To perform a BASIC program, you have to enter the BASIC environment, and then load the program source file, run. In the interpreted program, since the program always appears in the form of the source code, it is only a problem that the transplant is almost impossible to have a corresponding interpreter. Compilation programs can also be transplanted in source code, provided that it is necessary to compile different systems. For complex projects, it is indeed a small time consumption, and it is likely that some details are still necessary to modify the source. Code. Moreover, the interpretation program is compiled, and the modification of debugging is also very convenient. You can run immediately after editing. You don't have to make small changes every time you don't have to make a small change ... such compilation. Link process. However, everything is advantageous, because the interpretation program is to put the process of compilation in the implementation process, this determines that the interpretation program is destined to slow down in the compilation type, like a few hundred times the speed gap is not surprising. of.

Compiling type and interpretation type, both have a pros and cons. The former has a low speed of the program, which is low under the same conditions, so it is based on the development of operating systems, large applications, database systems, etc., like C / C , Pascal / Object Pascal (Delphi), VB, etc. They can be considered as compiled languages, and some web scripts, server scripts, and secondary development interfaces are not high, and the compatibility between different system platforms has certain requirements, such as Java, JavaScript. , VBScript, Perl, Python, etc.

转载请注明原文地址:https://www.9cbs.com/read-5166.html

New Post(0)