关于汇编的知识请移步文章 Assembly Language
We treat Computer Systems as a study of the interaction of hardware and software which determines the performance of computer systems.
Four architectural levels of computer systems
CPU & ALU
The components of a computer system
Types of computers
Computer generations
Backward (Downward) Compatibility for new hardware (向后/向下兼容)
Most software written for computers with old hardware can be run on computers with newer hardware.
VHDL (硬件描述语言)
Hierarchy of systems
Computers can always be viewed as hierarchical ordered systems which can be broken down into simple component parts in order to fully understand their operations.
Moore’s Law
The amount of circuitry (number of transistors) which can be placed on a given chip area approximately doubles every two years.
Windowing interfaces ---- WIMPs
A by-product of the microprocessor revolution, which allowed all users to have fast bitmapped graphics on their desks.
Trends of computing
John Von Neumann
An Austria-Hungary-born American mathematician. Made contributions to: quantum physics, functional analysis, set theory, topology, economics, computer science, numerical analysis, hydrodynamics.
Von Neumann bottleneck
CPU is continuously forced to wait for vital data (and instructions) to be transferred to or from memory.
指令和数据放在一起的后果是取指令和取数据不能同时进行,否则会引起访存的混乱。发展到今天,CPU的运算速度已经远远超过了访存速度,因此CPU必须浪费时间等数据。
由于指令与数据放在同一内存带来的CPU利用率(吞吐率)限制就是冯诺依曼瓶颈。
实际上,绝大多数现代计算机使用的是所谓的 “Modified Harvard Architecture”,指令和数据共享同一个 address space,但缓存是分开的。在内存里,指令和数据是在一起的。而在CPU内的缓存中,还是会区分指令缓存和数据缓存,最终执行的时候,指令和数据是从两个不同的地方出来的。可以理解为在CPU外部,采用的是冯诺依曼模型,而在CPU内部用的是哈佛结构。
————————————————
原文链接
为什么电脑还沿用冯·诺伊曼结构而不使用哈佛结构
Semantic gap
The term expresses the enormous difference between the way human languages expressing ideas and actions and the way computer instructions representing data processing activities.
Translation is done by special programs such as:
Compilers
: translating HLL instructions into machine code (sequence of instructions) before the code can be run on the machineAssemblers
: translating mnemonic form of machine instructions (like MOV, ADD, etc) into their binary codesInterpreters
: translating HLL instructions into machine code on-the-fly (while the program is running)Linking
Library files
/lib
and /usr/libe/
Interpreters ---- alternative way of running HLL programs
Java compilers and interpreters
Interpreters vs. Compilers
Interpreters as Virtual Machines
How to reuse existing proven software when developing new systems?
Source-level subroutines and macro libraries
Take copies of the library routines, edit them into your new code and then translate the whole together
Disadvantages:
Pre-translated relocatable binary libraries
Libraries are pre-translated into relocatable binary code, can be linked into your new code, but not altered.
Disadvantage : Each program is to have a private copy of the subroutines, wasting valuable memory space, and swapping time, in a multitasking system.
Dynamic libraries and dynamic linking
Load a program which uses “public” routines already loaded into memory, the memory-resident libraries are mapped, through the memory management system to control access and avoid multiple code copies.
Successful through Microsoft’s ActiveX standard.
Data
: raw facts, figures, measurementsInformation
: data organized into useful representationKnowledge
: application of reasoned analysis of informationMeasurement of Information
In 1948, motivated by the problem of efficiently transmitting information over a noisy communication channel, Claude Shannon introduced a revolutionary new probabilistic way of thinking about communication and simultaneously created the first truly mathematical theory of entropy. His ideas created two main lines of development: information theory and coding theory. Entropy of an event X is related to p(X).
如何理解信息熵
Alphanumeric codes
ASCII
: American Standard Code for Information interchange (7-bit code) and its extensions (8-bit codes)EBCDIC
: Extended Binary Coded Decimal Interchange Code (8-bit code). (IBM mainframe computersUnicode
: Recent 16-bit standardOnly half of possible byte patterns is used. The second half is used in the 8-bit extension to represent the codes of additional symbols, line shapes, foreign letters, etc.
The table is divided into two classes of codes
Limitations of ASCII code
Standard includes the European alphabetic scripts, Middle Eastern right-to-left scripts, and scripts of Asia, Africa and America, ideographic characters of China, Japan, etc
In a Java program, if you want to show some Chinese characters, you have to use their Unicode representations
Any representation of numbers capable of supporting arithmetic manipulation has to deal with both integers and real values, positive and negative.
使用补码表示整数 (Two’s complement)
原码,反码和补码
IEEE 754 standard :
IEEE 754 浮点数标准详解
Functions of OS : to interpret and carry out commands issued by users of the computer or application programs running on the computer.
Purposes
To realise the purposes of an operating system, the software system is often arranged in multiple layers.
Core of operating system: dealing directly with the hardware.
kernel
: device drivers, memory allocator, etc.
CLI (命令行界面)
: provide user accessibilities to the system
Many modern operating systems also allow for the simultaneous processing of multiple programs and support for multiple users.
Client
: The originator of a request
Server
: The supplier of the service
These are the minimum set of components for a working digital computer
Processor
:
CPU、Processor、Core的区别
Registers
:
small block of fast memory, temporarily store for data and address variables
Coprocessor
: microprocessors performing specialized functions that CPU cannot perform or cannot perform as well and as quickly
80486CPU 之前有协处理器,那时 CPU 算力较弱,现在 PC 一般不存在协处理器了。
On the motherboard, all the components are interconnected by buses (“signal highways”). A bus is a bundle of conductors, wires, or tracks. Typically, there are address, data and control buses, each including several signal lines
Each hardware unit is connected to all these buses. It is a simple way of building up complex systems in which each unit can communicate with each other. Little disruption when plugging in new units and swapping out failed units. The connected devices can have access to any signal line they require
The number of wires required for a bus is much smaller than that for point-to-point connections. But a bus can only transfer one item of data at a time, termed the Bus Bottleneck, it cannot be solved by simply increasing the speed of a processor.
The fetch-execute cycle or machine cycle is the sequence whereby each instruction of the program is executed
Execute phase depends on the type of instruction.
e.g. MOV AX, 256
CISC
: complex instruction setRISC
: reduced instruction setCISC 和 RISC 的区别
Hardcopy output
: graphics, lettersSoftcopy output
: video, audioParallel port
: printers, some scanners …Serial port
: modems, mice串并口
USB (Universal Serial Bus)
: replaced earlier interfaces, such as serial and parallel portsprotected by power surge protector or uninterrupted power supply unit (UPS)
EFLAG
: The Flag register holds the CPU status flags. It is a way of communication between one instruction and the subsequent instructions.Status flag
: The status flags are separate bits in EFLAG
where information on important arising conditions such as overflow
or carry bits
is recorded.数据结构-栈
The order of storing and retrieving the values for the stack can be described as LIFO
(last in, first out).
Operation of addition for n-digit numbers represented by 10’s complementary convention:
To subtract B B B from A A A one may first compute negated B B B and add it to A A A. Given B in 10’s complement, how to
compute − B -B −B:
If both inputs to an addition have the same sign, and the output sign is different, overflow has occurred.
浮点数表示法详解
Exponent biasing
The exponent is biased by 28-1-1, that is, biased by 127. Exponents in the range -127 to +127 are
representable. e=128 reserved for NaN, infinity
Special cases (e = 128)
Two main types of storage in a computer:
It refers to physical memory that is internal to the computer. The computer can manipulate only data that is
inside the main memory.
Random Access Memory. The name is to set it apart from serial tape storage with which you cannot access data stored in the second or following blocks without going through the first block of data.
The memory can be seen as a set of numbered storage elements, called words, each of which contains some
information. Each word is numbered with its address. Any word of memory can be accessed “without touching” the preceding words (Random Access) so the access time is the same for all the stored items.
There are two basic types of RAM :
Both types of RAM are volatile, they lose their contents when the power is turned off.
Read-only memory. Software stored inside also known as firmware. Helps boot up the system.
BIOS : Basic Input Output System
It refers to various techniques and devices for storing a large amount of data. Unlike main memory, mass storage devices retain data even when the computer is turned off.
Hard disk drives are the most important types of permanent storage used in computers. Hard disks differ from the other mass storage devices in three ways:
Each disk platter has its information recorded on both surfaces, each platter has two heads.
The information is recorded in concentric circles called tracks. Each track is broken down into
smaller pieces called sectors, each of which holds 512 bytes of information.
磁盘的结构
Addressing
CHS
: Cylinder, Head, Sector system, can be mapped onto LBA
.LBA
: Large Block Addressing, by absolute number of a sectorAssume that A piece of information needs to be read
CHS
or LBA
Disk cache
A portion of main memory used as a buffer to temporarily hold data for the disk. Because disks write operations are clustered, some data written out may be needed again (The data are retrieved rapidly from the disk cache instead of slowly from disk)
Retrieving files into RAM
is called reading. Copying data from RAM
onto a secondary storage device is called writing
It is the use of low-level memory to ‘expand’ high-level (main) memory. It provides a convenient expansion of main memory by ‘overflowing’ data and program code onto magnetic disk
The area on disk reserved for this purpose is known as the swap area
Improves flexibility but is slower than RAM to which the processor has direct access
Virtual Memory Management
Main memory is divided into frames
, often 4KB. The executable program is similarly divided into frame-sized chunks known as pages
. When a program is invoked not all the pages are loaded into main memory, only sufficient to get it started. The rest are copied into the swap area
When an instruction is needed from a page
not yet in the main memory it is loaded from the disk. If no empty frames exist at the moment the least used frame is freed to allow the new pages
to be loaded. (This is called swapping)
Virtual Memory Addressing
Within an user program addresses are in a form of 32 bit logical address.
In the case of 4KB paging system : – The lower 12 bits are ‘address within a page
’. The upper 20 bits serve as the ‘page
number’.
Memory Management Unit maps logical addresses into references to frame
numbers and addresses within the frames
Maximal memory length depends on address width.
Address width is determined by:
IP
, MAR
When the CPU sends out an address, a part of the address locates the correct chip, another part specifies an address within the correct chip
Why we need memory levels?
Registers
Registers are the memory cells which are core part of the processor itself. It has very fast access
Cahe memory
A memory placed between CPU and main memory. Contains a copy of the portion of main memory. The aim is to maintain in fast cache the currently active sections of code and data. Processor when needs some information first checks cache. If not found in cache, the block of memory containing the needed information is moved into the cache.
The idea of cache memory exploits Localisation of Memory Access principle: Computers tend to spend periods of time accessing the same locality of memory. Therefore, A portion of code or data which require access needs to be loaded into the fastest memory nearest to CPU. Other sections of the program and data can be held in readiness lower down the memory hierarchy.
Computer systems may be described at different levels of understanding. At the architectural level the computer is described as a machine for executing instructions.
Engineering model of the computer represents the machine as a complex electrical circuit. Within the circuit there are a large number of physical connections, along each of which a current may flow during the operation of the machine.
Presence of a current is used to represent transmission of the binary digit 1, while absence of a current represents a value 0
This kind of circuit is called digital electronic circuit, because the relevant characteristic is the presence or absence of current (digit 1 or 0), rather than the amount of current flowing
continuously variable values, along a range, such as temperature and pressure values
traditional analog recording devices are humidity recorders, mercury thermometers and, pressure gauges
standard telephone lines transmit analog signals
All operations that computers perform may be defined in terms of basic boolean functions, operating on bits
The digital electronic circuits and their components can be built from the devices implementing basic boolean operations – boolean gates (logic gates)
Boolean circuits
Elementary boolean gates can be combined into boolean circuits, implementing more complex boolean functions (operations). In fact, any boolean function can be implemented with this set of basic boolean gates
a definition of the function : Y = ( S ∧ A ) ∨ ( ¬ S ∧ B ) Y=(S\land A)\lor(\lnot S\land B) Y=(S∧A)∨(¬S∧B)
The circuit is a straightforward implementation of the function : O = ( A ∧ Z ) ∨ ( B ∧ Y ) ∨ ( C ∧ X ) ∨ ( D ∧ W ) O=(A\land Z)\lor(B\land Y)\lor(C\land X)\lor(D\land W) O=(A∧Z)∨(B∧Y)∨(C∧X)∨(D∧W)
The problem with the circuit :
So we need Two-line decoder
Given a truth table for a logic function, to implement the function by a logic circuit one may proceed as follows :