preface

Modern computer has developed very complex, it has become extremely difficult to understand the operation principle of the computer, although we can not make it, but we can understand how the computer system developed from zero.

Logic gate

Logic gates are the basic components of computers through which logical operations (also known as Boolean operations) can be performed, with only 0 and 1 inputs and outputs.

With the door

An and operation is performed, with two inputs and one output. The output is 1 only if both inputs are 1. Otherwise, the output is 0.

Or gate

Perform an or operation with two inputs and one output, and the output is 1 as long as one of the two inputs is 1.

gate

Perform the “not” operation, one input one output, taking the opposite signal of the input signal.

All logical operations can be performed through these three basic gates, and the essence of a computer is realized through these three basic gates, and calculation can be performed through thousands of logic gates.

add

Addition is the basis of all operations, so let’s see how to implement addition through the logic gates mentioned earlier. Computers are different from humans in the way of calculation. Humans usually use the decimal system, but computers are good at using the binary system.

XOR gates are a combination of three basic types of gates. XOR gates are structured as follows.

Shorthand for,

Combined into a half adder, as follows,

Remember as a,

The half-adder can only handle the addition of two binary one-digit numbers and cannot handle the carry calculated earlier. To handle carry, two half-adders can be connected to an or gate to form a full adder, as follows,

The full adder can only handle the addition of three binary one-digit numbers, one of which is the carry input. If you want to add n bits of binary data, you need to use n full adders connected together.

The reason why addition is the basis of all operations is that mathematicians have proved that other operations can be performed by addition, such as multiplication, division, square root, logarithm and so on.

Machine instructions

Although has the logic operation can help mankind to complete the calculation, but human direct such use is very unfriendly and inefficient, such as to do (11 + 22 + 33) + + 55 (44), we need to first three inputs and additive respectively, and then manually recorded the intermediate results, similarly need to record another intermediate results, Then add the two numbers again.

To automate this process, humans developed memory, which can be used to store data. Memory can be thought of as blocks, each of which has an address, through which data can be stored, read, and modified. I’ve put all the relevant data in memory.

  • Read the number of address 000 to the adder
  • Add the number of address 001 to the adder
  • Add the number of address 002 to the adder
  • Save the adder number to 003
  • Read the number of address 004 to adder
  • Add the number at address 005 to the adder
  • Save the number of the adder to 006
  • Read the number of 003 address to the adder
  • Add the number at address 006 to the adder
  • Stop adder.

This process involves four operations, load, Store, Add, and halt. These operations can also be coded, such as 100, 101, 102, 103. The above procedure can be performed with the following instructions.

load 000
add 001
add 002
store 003
load 004
add 005
store 006
load 003
add 006
halt
Copy the code

The corresponding instruction code is,

100 000 102 001 102 002 101 003... 103Copy the code

With the above instructions, save them in memory so that the computer can execute them one by one, without human intervention, until it runs to the stop instruction, the whole process is automated.

The above is a brief introduction to instruction operations in terms of addition operations, but real computers need more instruction sets, which require more hardware to support. There are two ways to design the instruction set of computer system: (1) design the simple instruction set, and then realize the complex calculation by programming. ② Design complex instruction set, directly through the hardware to achieve complex instructions, this calculation speed is faster, but increase the complexity of hardware and cost.

register

In the actual hardware design, because the calculation process often involves some commonly used numbers for operation, so the special design of the register for the need to transfer the data for temporary storage, this kind of temporary storage mode is far faster than the memory mode, the speed is so fast that it can be very good CPU execution. Similar to the previous adder, the result of the calculation is saved in the adder.

The first shows a direct speed comparison between different stores, and the second shows some examples of instructions.

A programming language

Through the design of the logic gate and the realization of all kinds of operation instructions, such a computer system design is completed. When a computer is running, it can perform calculations and operations by reading program instructions stored in memory.

Machine instructions like 100, 000 are hard for humans to remember, so they are encoded in forms that humans can easily remember, such as Load 000, or assembly language. But assembly language may not be friendly enough for humans, as in the following,

On the left is the high-level language C language, and on the right is assembly language. It can be seen that although assembly has been much more convenient than machine language, but compared with high-level language, assembly is still too troublesome and inefficient, which is also the reason for the birth of high-level language.

This introduced a high-level language and required an additional compiler to translate the high-level language into assembly language. Then the whole process is: high-level language -> assembly language -> machine instructions ->CPU execution.

The operating system

From the logic gate to the programming language of the computer system do are calculated, such as subtracting, if it can only be used for calculating estimates there will be no so many people with computer, so it has a screen, along with the development of the computer has a variety of audio input and output, a keyboard, mouse, so that the computer can do more things, such as game film.

Add so many devices to the computer system, to interact with these devices on the need for a variety of drivers, in order to facilitate their connection and work together, the operating system, through the operating system can be the underlying hardware different implementation shielded, and it also provides a lot of system calls to achieve a variety of functions.

conclusion

The above introduces the relevant principles of the computer. From logic gates to machine instructions, to registers, to programming languages, and finally to operating systems, computer systems have grown from zero to today’s super-complex systems.

————- Recommended reading ————

Summary of my open Source projects (Machine & Deep Learning, NLP, Network IO, AIML, mysql protocol, Chatbot)

Why to write “Analysis of Tomcat Kernel Design”

2018 summary data structure algorithms

2018 Summary machine learning

2018 Summary Java in Depth

2018 Summary of natural language processing

2018 Summary of deep learning

2018 summary JDK source code

2018 Summary Java concurrency Core

2018 summary reading passage


Welcome to: Artificial intelligence, reading and feeling, talk about mathematics, distributed, machine learning, deep learning, natural language processing, algorithms and data structures, Java depth, Tomcat kernel and other related articles