Compiler for operating system, CPU, compiler, runtime library, system call relationship

Source: Internet
Author: User
Tags constant

Operating system, CPU, compiler, runtime library, system call. This is a relatively tall concept in computer science, and many trained are not even clear about a simple code execution process, which block is the operating system control, which is the compiler control, what role the CPU actually played, what is the runtime library.

Thinking about the problem, we must first grasp the macro, grasp the general situation, and then to their own interests of the node to do in-depth analysis. This is a very practical way of thinking about the problem, will not let you fall into the "local optimal solution", more importantly, it can give you a deeper understanding of the nature of the problem, not confused when encountering difficulties. This article will comb some of the basic concepts in computer science, and we'll go through the process from birth to extinction, explore CPUs, explore compilers, explore operating systems, and run-time libraries to gain a deep understanding of computer systems.


compiler


Compiler is absolutely the realm of the hall of Computer science, can write compiler is the Daniel, I vaguely remember my undergraduate to do compiling principle of the situation, that 4 8K of paper Leng did not draw a simple language syntax state transfer diagram. Today, we don't talk about the compiler principle, just focus on its role. compilers are high-level language-to-machine language converters . When you voluminous 10,000 lines of code, those struct, if, while except you and C compiler to understand, no one can understand, machine is no exception. The machine can only read 01 yards, the compiler is responsible for translating the source code into 01 yards. Windows. exe suffix program is a string of 01 yards, Linux your a.out is also 01 yards, but 01 yards definitely more than these, Linux under the. O and the. dll under Windows are also 01 yards, except that these 01 yards cannot be executed directly, but are called by a.out and. EXE programs.

This is the compiler, in fact, you just remember that it is a high-level language to machine language converter can, this kind of work in real life called: translation. With the compiler, your mind will crystallize to 01 yards.

Not so simple, we have to go deeper. All know that the program includes code and data , for the code actually we can have a sense of understanding, this is mainly because everyone has learned assembly language, the level of code compilation is basically translated into Mov,jmp,add, and I believe many people have written similar code, But what about the data. how the Compiler "compiles" data .

You should despise me: How can the data this thing "compile"? Yes, the data is really not compiled, and you can say that it is "placed" in a location by the compiler, but there is definitely more to the understanding of the data. First, there are significant differences between global variables and local variables , as well as the seemingly simple but intelligent basic data Types (int,short,double, etc.), and the cliché strings .


global variables and local variables


The final executable file is stored in 01 yards, which has been determined. Analyzing a typical executable file, using an elf file (Linux executable file) as an example, found that the final 01 yards consisted of the following parts: static data area, code area, string constant area, and so on. Where your global variables are stored in the static data area of the elf file, the code is stored in the code area, and the string "Hello World1", as declared in the following way, is stored in the string constant area:

char *str ="Hello world1";

There are also local variables. Remember that there is no local variable in the 01 yards of the executable because the local variable is placed in the program's stack space . When it comes to stacks, stacks are only a concept when the program is running, so there is no block similar to "local variables" in the 01 yards generated by the compiler. Strike while We have solved the placement of the code, global variables and the placement of strings, then the local variable is how to place it, it will not appear for no reason. The so-called local variables are variables defined inside the function, such as the following functions:

                                                           
 int func{
    int A;
    Char b[2];
}

Where A and B are local variables, local variables are in the stack space of the function. For example, when the function func is called, the stack of the program will be the following state:


Since the stack is a dynamic structure, it is only involved when the program executes, so a and B variables are definitely generated during the execution of the program. So it is not difficult to understand that each of the sub-function assembly code in the initial part of the process will certainly have a compression stack, the above example is pressed into 1 int and 2 char. References to A and B in a child function are associated to this area on the stack. Therefore, local variables and global variables are fundamentally different: global variables exist in 01 yards, are static, and local variables in 01 yards is only a few push variables, is dynamic; Global variables will accompany the entire program execution process, while the local variable lifetime is just a short sub-function execution time.


Basic data Types


Almost all of the introductory chapters of the C language textbooks are basic data types, where we don't talk about the difference between strong data types and weak data types, and a little bit of dry stuff. Why would you say a data type ? From one of my own doubts. Learning computer over the years, whenever I encounter data type problems, my ears are always filled with various sounds: data types and compiler-related, data types and operating system-related, data types and CPU-related, data types and platform-related. Exactly what the data type is related to.

You might want to analyze it all. First, the data type must be CPU-related, such as the sizeof (char*) return value of 32-bit and 64-bit CPUs, which is different because of the different types of CPU data. And compilers are certainly relevant, the data type includes not only the size of the memory that the type occupies, but also the actions that are applied to that type (this definition is similar to the class in C + +, except that the data should have functions). In a data type conversion operation, the behavior of different compilers is not the same. For example, the unsigned char type has a strong-to-long type, and some compilers may assign a long 3 byte to a value of 0xFF, while some compilers assign these 3 bytes to 0x00. In this way, the same operation produces different behaviors and results on different compilers, which are all static 01 yards of the corresponding program, so the data type is related to the compiler. For the operating system, because it is just a program, is a "government program", itself built on the CPU, it cannot be said that the data type is related to the operating system.

Well, the analysis here, I basically came to the conclusion that the data type is CPU, compiler-related, this is what some people talk about the platform. As for the operating system, let's just think of it as an ordinary program, but it has resources in its hands.

Speaking of which, the compiler is done. Yes, the compiler is used to generate 01 yards, the process of generating a variety of wisdom. At this stage, the program is still lying on the hard disk of a code, quietly waiting to execute.

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.