Introduction to Computing (2) Basic Principles of Computer and Program Operation

This article is a note and summary of the 李戈teacher's 计算概论与程序设计基础course in the School of Information Technology of Peking University . The source course address

The past and future of computers

what is计算机

计算机Origin of the name:

  • The English word "computer" officially appeared in 1646
    • At the time it was someone who specialized in computing
  • The machine used for calculation was called "calculator" or "tabulation machine" before 1940
  • It wasn’t until the first electronic computing device was invented around 1940 计算机that the term officially has today’s meaning.

计算机It is a device that can receive input, process data, store data and generate output according to a series of stored instructions

Computers in history

Since there are many computer history content introduced in the course, I will not list them one by one, but briefly introduce some more relevant to the article.

Generally considered第一台计算机

ENIAC: Full name Electronic Numeric Integrator and Computer, called电子数字积分计算机

As shown:
image

  • J. Mauchly and J.
    Eckert , Moore College, University of Pennsylvania
  • Started in 1943, completed in 1945, officially launched on February 14, 1946
  • 17,468 electronic tubes, 7,200 diodes, more than 70,000 resistors, more than 10,000 capacitors, and 6,000 relays, with as many as 500,000 welding points in the circuit; 174,000 watts of power consumption
  • 30 meters long, 3 meters high, 30 tons weight, covers an area of ​​170 square meters
  • 5000 additions per second can complete two 10-digit multiplications in 3/1000 seconds

ENIACShortcomings:

  • ENIAC is not a stored program computer
  • Programming is carried out by manual wiring

From ENIACtoEDVAC

EDVAC: Full name Electronic Discrete Variable Automatic Computer, called电子离散变量自动计算机

As shown:
image

  • In March 1945, the pioneer of computing technology 冯·诺伊曼(John von Neumann) came to Mauchly and Eckert at Moore College for a two-day discussion and drafted a program for a stored-program electronic computer. The plan was 冯·诺伊曼compiled and published in June 1945——存储程序控制原理
  • EDVAC Manufactured in 1952
  • EDVAC Is the world's first stored program computer
  • Is the prototype and template of all modern computers

Modern computer

Full name: 通用电子数字计算机(General ‐Purpose Electronic Digital Computer)

  • General purpose: A computer is a general information processing device, as long as there is suitable software, it can be used for various purposes
  • Electronics: It is the physical basis of computer hardware realization. The operation of the computer is ultimately realized through the current and potential in the electronic circuit
  • Digitization: It is the way of computer information representation. All information, whether originally numerical, text, graphics, sound, etc., is unified into a binary digital representation in the computer. Digitization is a basic feature of computers and an important foundation for versatility

Brand new computer theory and calculation model

With the failure of Moore's Law, people need new computer theories and calculation models. Including but not limited to 量子计算机and 生物计算机etc.

The proposal of quantum computing

In 1982, Richard Feynman put forward 利用量子体系实现通用计算the idea in a famous speech . He found that the computational power required to analyze and simulate the world of quantum physics far exceeds the capabilities that can be achieved by classical computers. Using a controllable quantum system (for example: a quantum computer) to simulate and calculate another quantum system of interest (for example: the universe) will be very efficient

Quantum computing VS classical computing

Classic calculation:

  • A bit can only hold one state at a time
  • For example: Two bits, only one of the following situations can be stored at a time:
    • 00011011

Quantum computing:

  • A qubit can hold multiple states at the same time
  • For example, two two-word bits can store all of the following conditions at the same time:
    • 00011011

In theory, 300 qubits carry data that is 2 to the 300th power, which will exceed the total number of atoms in the entire universe.

However, in reality, it is necessary to correct errors in the calculation process, and many physical qubits are required to obtain a fault-tolerant logical qubit. Therefore, about 1,000 physical qubits can obtain computing power beyond classical computers.

A lot of basic principles and knowledge of quantum computers are also popularized in the course, and interested students can listen to it.

计算机的过去和未来Let's stop here first, let's turn our eyes back 现代计算机and learn 程序运行的基本原理.

Basic principles of program operation

We 计算概论(一)already know in:

Circuits can complete calculations, so you can design addition, subtraction, multiplication... various circuits... and use them to complete various types of calculations.

So, is it possible to:

  • What calculations need to be completed, design a corresponding circuit!
  • I have designed many atomic circuits, and I will temporarily assemble them when needed!

ENIACIt is such a machine, and history has proved it to be outdated.

Therefore, you cannot complete new calculation tasks by re-"combining different circuits"!

Instead:

  • Control the computer through a certain command, and let the computer run according to this command, which can be represented by an electrical signal;
  • This kind of command is not "temporarily input" to the computer, but is stored somewhere and can be changed at any time;
  • When the command is changed, the function of the computer is also changed!
  • This is it EDVAC!, the first in the world 存储程序计算机. Computers now areEDVAC

what is存储程序计算机

存储程序计算机Also called冯·诺伊曼式计算机

  • In 1945 von Neumann to 关于EDVAC的报告草案the title, it drafted a 101-page summary report.
  • EDVAC It was the world's first computer with stored programs and became the prototype and model of all modern computers.

Technical features

  • 6000 tubes
  • 12000 diodes
  • Power 56KW, weight 7850KG
  • Covering an area of ​​45.5 square meters
  • Need thirty people to operate at the same time

冯·诺伊曼式计算机Structure:

Insert picture description here

Controller

  • Command and control the coordination of computer components

Arithmetic unit

  • Perform arithmetic and logical operations on data.

Memory

  • Store the information to be operated and intermediate
    results, including machine instructions and data.

Input device, output device

work process

  • In 控制器the command, from the 存储器extracted instructions
  • Analyze the instruction, get the calculated 命令sum 待操作的数;
  • 存储器Take the number to be calculated from the top and put运算器
  • 运算器Calculation results
  • Output to 存储器or输出设备

Let's first look at the classification of storage

Classification and characteristics of storage

The classification is as follows:

  • register
    • Inside the CPU, used to store the operands and results
  • cache
    • Usually inside the CPU, used as a data buffer
  • RAM
    • The part of the CPU that you want to put but can’t put
  • External storage

Register characteristics

  • Working speed is consistent with the beat of the CPU computing unit
  • Time access to data about spending 0.x纳秒time
  • 寄存器Directly connected with the computing unit, the computing unit directly 寄存器performs read and write operations
  • 寄存器High production cost, generally only a few registers are equipped in CPU chips

CACHE (cache) feature

  • The internal cache of the CPU is called 内部高速缓存(Internal Cache)
  • The cache on the motherboard is called 外部高速缓存(External Cache)
  • Usually divided into multiple levels, the working frequency is different between different levels
  • Generally read and write once in nanoseconds
  • Different capacity (nK-nM)

Memory characteristics

  • Internal memory, referred to as memory
  • Store operation data in CPU
  • Store data exchanged with external storage such as hard disk
  • Temporary storage, power loss
  • Low price and easy to replace
  • The working frequency is getting closer and closer to the CPU working frequency, but there is still a gap

CPU data reading rules

When the CPU reads data

  • Find it from the cache first and read it immediately if found;
  • If not found, read from the memory at a relatively slow rate and send it to the CPU for processing
  • At the same time, transfer the data block where this data is located into the cache
  • It is possible to read the entire block of data from the cache in the future without calling the memory.

Minimize possible "slow" read operations;

Principle of locality

  • CPU access to data usually has a certain locality:
    • Temporal locality: If a memory address is being used, it is likely to be accessed again in the near future
    • Spatial locality: the information that may be used in the near future is likely to be adjacent to the currently used information

Storage related name explanation

RAM(Random Access Memory)

  • DRAM(Dynamic RAM): Random access, but must be refreshed periodically to keep the stored content
  • SRAM(Static RAM): A memory that can be accessed randomly and does not need to be refreshed periodically
  • EDO DRAM(Extended Data Out DRAM) Extended Data Out Dynamic Memory
    • Visit the next page while sending data to the CPU, thereby improving work efficiency (about DRAM15~30% faster than the traditional one ).
  • SDRAM(Synchronous DRAM) synchronous dynamic memory
    • It works on the frequency of the CPU external bus and is synchronized with the CPU clock.
  • DDR(Double Data Rate SDRAM) double data output synchronous dynamic memory
    • DDR SDRAMIn theory, RAMthe speed can be doubled, and it can read data on both the rising and falling edges of the clock.
    • DDR2 Voltage 1.8v, high-end frequency up to 1000MHz
    • DDR3 Voltage 1.5v, frequency up to 2000MHz, 8bit pre-reading
    • DDR4 Voltage 1.2v, data transmission rate 3.2GT/s

ROM(Read Only Memory)

  • ROM(Mask ROM): It is written during ROM production and cannot be changed by the user
  • PROM(Programmable ROM, fuse PROM): blank during production, user can write in, but cannot be changed after writing
  • EPROM(Erasable PROM, UV EPROM): Can be erased and rewritten, but special equipment must be used
  • EEPROM(Electrically EPROM)
  • Flash EPROM (Fast erasable programmable read-only memory)

Why can the memory store numbers?

This question is actually asking: How to store data through circuits?

First look at a 循环或circuit:

image

Please simulate as follows:

  • Initially A, Binputs are 0, the circuit output is 0
  • At this point, Athe input state we are trying to change is 1
  • The circuit output is 1, and Bthe input state will also change to 1.
  • After that, no matter how it is set A, the output is always 1

Look at another 循环与circuit:

image

Please simulate as follows:

  • Initially A, Bthe input is 1, the circuit output is 1
  • At this point, Athe input state we are trying to change is 0
  • The circuit output is 0, and Bthe input state will also become 0 at the same time
  • After that, no matter how it is set A, the output is always 0

According to the above two simple circuits, we have a circuit that can store 0 and 1 separately (unless the power is turned off). The disadvantage is that it cannot be modified.

Then we optimize the combination of these two circuits, and we get one 锁存器:

image

Please simulate as follows:

  • Set RESETto 1 (start reset), the circuit output is 0, and the loop circuit output is 0
  • Set RESETto 0 (turn off reset), SETset to 1, the circuit output is 1, the loop circuit output is 1
    • If the reset is not started at this time, no matter SETwhat value is set, the output state of the circuit is always 1
    • In this way, the function of saving data 1 is realized
  • Then I want to change the data to 0, what should I do?
    • Will be RESETset to 1 (start reset)
    • Will be RESETset to 0 (turn off reset)

At this point, we can answer the question just now, 锁存器and read and write a Bit through the circuit.

However, on this basis, another 门锁structure is optimized . Let's look at the circuit diagram:

image

Command execution

We already know:

  • The CPU circuit can perform calculations;
  • Von Neumann Computer
    • No need to "plug in" temporary combination circuits to complete different tasks
    • To complete different functions by reading and executing "stored" commands;

Then we come to understand the knowledge related to command execution.

Instruction Set

  • A set of instructions used to calculate and control a computer system in a CPU
  • Pre-defined during CPU design
  • It is an important indicator of CPU performance.

Like Intel X86指令集, ARM指令集wait

instruction

  • The final manifestation is binary code
  • Its length varies with different CPU types;
  • Contains one or more bytes
  • Contained 指令码and操作数
    • 指令码 Explain what to do
    • 操作数 Refers to the number or address to be operated

CPU working mode

Now that we understand the 储存实现sum 指令集概念, let's take a brief look at how the CPU works.

image

  • ALU: Arithmetic Logic Unit

    • Digital circuits dedicated to performing arithmetic and logical operations.
  • register

    • Accumulator AC: temporarily store the calculation result of ALU
    • Status condition register PSR: ALU operation result, system working status information
    • Data register MDR: buffer data
  • Controller

    • Program counter PC: store the address of the next instruction
    • Instruction register IR: store the currently executing instruction
    • Address register MAR: store the main memory address to be accessed

Program execution

Understand 指令的执行, how does the program we write execute? What does it have to do with instructions?

Look at the following process:
image

  • First, use high-level language to write program functions to achieve
  • Compiled into assembly language by a specific compiler (a program may be converted into multiple instructions)
  • Assembly language is then compiled into machine instructions, which are then executed by the CPU
  • The entire execution process is completed in memory, and the code and related data are stored in different areas of the memory
  • The entire execution process is executed continuously and sequentially under the coordination of the controller.

We look at the execution process:
image

to sum up

Through the two articles of Introduction to Computing (1, 2), we know:

  • Computers can calculate with circuits!
    • Numbers -> Binary numbers -> can be calculated with Boolean operations -> can be realized by circuits
  • CPU is a manufactured circuit, it can complete the operations in the instruction set!
    • The instruction is a binary code that the CPU can understand and execute it;
  • If you want the CPU to do things according to our ideas, you should:
    • Write what we want to do in a programming language
    • Translate this written thing into a binary instruction that the CPU can understand

The content of this part is learned JVMsynchronously while studying, and you can always find some similarities. The computer design is really great, hahaha.

This is the end of the introduction to calculation, and then we will attack with all our hearts Android binder.

Guess you like

Origin blog.csdn.net/lijie2664989/article/details/107899265