Computer systems consist of hardware systems and software systems that work together to accomplish the task of executing the program. As one of the greatest inventions of the 20th century (the world's first computer ENIAC and the University of Pennsylvania, which was born in the United States in 1946 ), computer systems can be said to be the most sophisticated and sophisticated tool ever created by humankind. Today, with the help of the computer community's Bible textbook, "in-depth understanding of computer systems," I'll take you through the secrets of computer systems.
1 information is bit + context
Computer is the product of information science, which is mainly about helping people to deal with all kinds of information. And the information itself is a relatively abstract concept, from the definition given by the Baidu Encyclopedia , we can know that information is used for transmission and processing. and information must have a carrier, that is, there is a form of expression. So how does the information in the computer be stored and transmitted? This is about the topic of our section: information is a bit + context.
All the information in the computer is stored in the form of bits, and understanding this can help you understand a lot of problems. For example, many beginners do not understand the text files and binary files to distinguish. In fact, no matter what file, in the computer all is ... 01101100 ... such binary code. So all files can be said to be binary files, and text files is just a special binary file. Where's the special? It is special in the computer to its "translation". We humans are not very able to deal with ... 01101100 ... this kind of thing, so the computer to translate these binary representations of the information we are familiar with the text, pictures, sounds and other multimedia information. Of course, the translation rules between different multimedia information and the two-tier system are different, in which a translation rule between binary and text is called ASCII encoding. ASCII encoding allows for one by one correspondence between 8-bit bits and individual characters. The file that uses ASCII encoding to convert text information into binary systems is called a text file. In view of this, we can divide the binary files into text files, picture files, sound files, and so on. In short, in the computer, we are familiar with the various information is encoded into a binary form of storage and transmission.
As mentioned above, the conversion rules between different types of information and binary are different. You can not put your favorite songs in the form of pictures open, nor can you convert your photos into text (of course, the conversion is possible, but the result is certainly not what you want, recall that there has been a full screen garbled experience). In other words, binary information is also typed, and these types are represented in the file in which the information resides, that is, the binary code. In this way, there are interrelated relationships, and a bits is given different meanings in a particular environment. Again, we have to understand or translate them, and we must also understand them according to the context in which we speak.
Information is encoded into a piece of interrelated binary code stored in a computer system, which is stored, passed, and processed in binary form. Only when interacting with humans, as shown on the screen or printed out, will it be translated into familiar forms.
2. Programs are translated into different formats by other programs
Before we said the main function of the computer is to process information, that is, processing ... 01101100 ... this binary code. There's obviously a problem with computers as a life-without-intelligence thing, how does it know what to do with information? Of course, that's our software or the program. The software system is only the indispensable part of computer systems, because the process of information processing must be done by software, and a computer system that cannot process information has no meaning. As a result, people invented software that gave life to computer systems.
How to tell the computer how to process information? Since the computer can only store binary code, so people naturally think of using binary code to control the computer system, yes, this is the birth of machine language! Binary code has also become binary. But earlier we also mentioned that humans are not adapted to deal with ... 01101100 ... this kind of thing. So at that time, people and computers "communication" cost is very large, and inefficient. In order to overcome this difficulty, invented another means of communication, that is, the machine code to write a translation software, and then we use some mnemonic to express what we want to do, and then use the previous translation software translated into binary machine code, and finally let the computer system to execute the code. With this "division of technology to make Yi" strategy, the software industry has taken a big step forward, and people will be composed of these mnemonic language known as assembly language. The next thing is logical, people also found that assembly language is too difficult to use (people always feel that the existing things difficult to use, which is also the important power of human civilization forward development), and then invented the C language, C language closer to natural language, coding style is more flexible, deep user favorite. But mankind is not satisfied, and later invented the C + +, Java and other languages. These languages are closer to the real world and away from the pesky binary code at the bottom.
Back to the title of this section, now that programmers are writing programs using the so-called high-level language, it is necessary to understand how a computer translates our code into two-level code. Here we take the compiled language as an example to illustrate some of the steps that have gone through: The first is the text file we wrote (why a text file?). Because we are more familiar with the text, these files are processed by the preprocessor "physical", producing an intermediate product (or text file), and then our play, the compiler translates the text file "intelligently" to the assembly file, and then the assembler, which translates the assembly file into a machine-familiar binary file, Finally, a connector that links multiple files to a computer system for execution.
Here to focus on the role of the compiler, the pre-processor and the following assembler and the linker do is a fixed one-to-one translation work, only the compiler is "intelligent", this intelligence is embodied in the optimization capabilities. First of all, in a specific hardware platform, the assembly code and machine code is one by one corresponding, from the assembly code can be fully computer system running process, so the most basic program debugging is assembly language rather than machine code (of course, if you like to see the machine code is also possible). In this case, we want to correspond to the two ends of the compiler translation: source code and assembly code, not one by one corresponding, the same source of code in different cases (with the compiler type and optimization level) will be translated into different assembly languages by the compiler. So the compiler is a very complex and important software system, the programmer's life has been dealing with it!
This section is about why and how the programming language we use is converted in the computer. The build system builds bridges between our code and machine control .
3. It is beneficial to understand how the compilation system works
The compilation system is an intelligent translation system, but its intelligence is also very limited, it requires the programmer must be in accordance with the established format to organize the code, otherwise, it may "misunderstand" our meaning. These established rules are the grammar of a language, and we must write the program in strict accordance with the syntax, otherwise the compiler will make an error saying that the translation cannot be completed. But this is just the beginning, writing a program to control the computer is a complex process in which a variety of errors or flaws affect our control effect. To get the job done better, we need to understand if the compiler is working.
Understanding how the compiler works, at least to understand the key points, is very necessary for programmers, especially C programmers, and it allows you to work more harmoniously with the compiler. Specifically, there are several benefits: optimizing the performance of the program, you can improve the efficiency of the program at the language level, understand the link error, I believe that most C + + programmers have experienced unresolved external symbols bar, and so you understand the compiler's link process, you can understand what this means; avoid security vulnerabilities , buffer overflow is a notorious program bug, and the knowledge of the function call stack helps you understand and avoid this error.
The learning compiler does not work as well as other techniques, and it quickly improves the level of programming. This knowledge is more like the internal strength of martial arts novels, is the basis for further improvement of programmers.
4. The processor reads and interprets the commands stored in the memory
The source code we write is processed by the compiler, and eventually it is converted into binary code that is stored in the compute memory. Memory can be seen as a data warehouse in which a large amount of data is stored in binary form. There is our program code, which is executed through a physical component called a processor, which controls the operation of the entire computer system.
The entire running process of a computer system can be seen as the process by which a processor reads instructions from memory (a new name in the code) and executes instructions. The effect is that the processor does a variety of tasks according to the command control peripheral components. Here is the computer architecture of von Neumann: Memory, is our memory, all the data are put here; the controller, which is part of the processor, uses the "pulse" generated by the clock signal to control the operation of the other parts, which is also part of the processor, which is used to complete simple arithmetic/ Logical operations, these simple operations constitute the basis of the system processing data, input, these things are used to complete human-computer interaction, such as mouse, keyboard, monitor and so on.
Throughout the system, data is moved from one location to another over and over again. It can be thought that the process of system operation is the process of transporting data. Therefore, the data transmission efficiency is the key factor to determine the overall efficiency of the system, in order to improve the efficiency of data transmission, the computer system uses a lot of technology, understand these technologies and reasonable use can greatly improve the program performance. Here are some things to know about this.
5. Cache is critical
For a particular memory piece, its access speed and capacity are counter-correlated. In other words, the larger the storage capacity, the slower the access speed. The fastest storage device in a computer system is a register, and its number is only a few or more than 10. The hard disk with the largest amount of storage, the access speed is the slowest. A machine's hard disk capacity may be 1000 times times larger than its memory capacity, but its access speed may be 10 million times times slower, in order to adjust such a large speed gap, computer systems using multi-level caching method.
The role of caching is simple, it simply reads the data that the processor is likely to use in advance from a memory piece that is slower than the larger reading speed for the processor to use. In order to adjust the effect, the new system now uses three-level cache technology, that is, from memory to register to insert three layer storage devices, they are smaller and faster.
6. Storage Device Formation hierarchy
As mentioned above, the various memory pieces in a computer system are sorted according to their capacity or access speed, thus forming a hierarchical structure. The top is the register, the following is the cache at all levels, then the memory, then the hard disk, and finally possibly network resources.
Memory is a sub-structure, because the physical characteristics of its storage and reading speed must be inversely proportional. In order to better exchange data between a fast device and a slow device, you need to insert an intermediate layer in the middle. Compared to the specific implementation details, this design idea is more worthy of our learning.
7. Operating System Management hardware
We write the program is mainly logical expression, but really in the computer system running, but always and specific hardware to deal with, we are unlikely to write every time the program is spent on managing every byte of memory, and should not think about the screen each pixel how to control. In order to make the hardware system transparent to the ordinary programmer, the computer system uses the operating system to unify the management hardware, our application only needs to communicate with the operating system.
With the help of the operating system, we can abstract a variety of hardware devices into a unified model to manage the use, without having to ignore the specific implementation details. Specifically, I/O devices are abstracted into files, memory and I/O devices are abstracted into virtual memory, and processors, memory, and I/O devices are abstracted together as processes. Let's make a brief introduction from the big to the small.
Process, when a program is executed, we can consider this program to monopolize the entire computer system, a program that occupies the CPU, memory, I/O device "illusion" is realized through the concept of process. The process by which the operating system controls the entire computer can be seen as the process of managing the process tables, and the operating system switches back and forth between processes that are different from one rule to another, accomplishing parallel tasks. We execute a program that has one more process in the computer system.
Virtual memory, which is an abstraction of memory areas and I/O devices. Programmers usually say that the global variable area, heap area, stack area and so on are virtual memory abstract concept, and the real memory is not divided these things, their hardware base is exactly the same. The reason for this abstraction is that programmers use memory conveniently, and the memory and hardware memory that programmers see is a fairly complex process.
files, files for every person who used the computer is not unfamiliar, in fact, the essence of the file is some byte sequence. All of the hardware devices that can read and write are abstracted into files, and programmers just need to read files or write files, without having to relate to how the specific hardware is written and read.
The purpose of modeling hardware is to make it easier for people to use them. With all these abstractions, programmers are freed from tedious hardware details. This method of problem solving is very common in the whole computer and even information field, and it is the perfect embodiment of human ingenuity.
8. Using network communication between systems
A computer system is so powerful because it can process data itself, but it can also communicate across space. Computer network is more than the computer system itself and the important product, it is with this network, human society has undergone tremendous changes.
Although the concept of the network is very important, but here is not intended to introduce too much network knowledge, for a computer system, the network is the equivalent of a file, we can read from the data can also be written in the data, to understand this for the programmer.
9. Key Themes
Concurrency and parallelism are key concepts in the speed of current computer systems, and they all involve the ability to handle multiple transactions at the same time. Just as people can not use the same as two, computer system concurrency is more difficult, decades of research has just entered the practice. This should be one of the hottest topics in computer research.
Abstract is a high-level embodiment of human thinking, in computer systems, people use a lot of abstraction to help us complete the task. In other areas, the meaning of abstraction is also very important, which in the programming language also has a lot of embodiment, such as the concept of interface, is the abstraction of a set of functions.
a computer system is used to process information, which is stored in a system in binary form. In order to realize the control of computer system, we must write code to complete. Compilers are tools for interpreting our code, and understanding how the translator works helps us write more secure and efficient code. The processor is the device that executes the code, in the process of processing the data, the data transmission is very common in the system, in order to improve the transmission efficiency, adopt the idea of fast cache to adjust the difference of access speed of different hardware. Abstract is a very important concept, whether in computer systems or in other areas, learning abstract thinking is more important than learning specific techniques.
Computer system roaming