73
Computer Organization Chapter 5 天天天天天天天天

Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

Embed Size (px)

Citation preview

Page 1: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

ComputerOrganization

Chapter 5

天津大学软件学院

Page 2: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 3: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

虚拟机 , virtual machine• 计算机系统由硬件 (Hardware) 和软件 (Software) 组成• 传统机器级以上的所有机器都称为虚拟机 , 由软件实现

- 软硬件的功能在逻辑上等价 , 即绝大部分硬件的功能都可用软件来实现 , 反之亦然- Level n 提供了对 Level n − 1 及以下层次机器的虚拟

Page 4: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

计算机硬件的组成

• 仍然遵从 von Neumann 体系结构 , 主要包括– 中央处理单元 CPU( 控制器、运算器、寄存器 )– 存储器 ( 内存储器、外存储器 )– 输入输出设备– 互连设备

Page 5: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 6: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 7: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

CENTRAL PROCESSING UNIT (CPU)

The central processing unit (CPU) performs operations on data. It has three parts: an arithmetic logic unit (ALU), a control unit, and a set of registers.

central processing unit (CPU) :中央处理器arithmetic logic unit (ALU) :算术逻辑单元,运算器control unit :控制器register :寄存器

Page 8: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Registers are fast stand-alone storage locations that hold data temporarily.

Data Registers (数据寄存器) Today, computers use dozens of registers inside the CPU to

speed up the operations because, increasingly, complex operations are done using hardware (instead of using software) and there is a need for several registers to hold the intermediate results.

Instruction Register (指令寄存器) Today, computers store not only data but also the

corresponding program inside memory. The CPU is responsible for fetching instructions, one by one, from memory, storing them in the instruction register, interpreting them, and executing them.

REGISTERS( 寄存器 )

Page 9: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Program Counter (程序计数器)

The program counter keeps track of the instruction currently being executed. After execution of the instruction, the counter is incremented to point to the address of the next instruction in memory.

CONTROL UNIT( 控制器 )

The control unit is like the part of the human brain that controls the operation of each part of the body. Controlling is achieved through wires that can be on (hot) or off (hold).

Page 10: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

The arithmetic logic unit (ALU) performs arithmetic and logical operations.

Arithmetic Operation (算术运算) The simplest unary operations are increment (add 1) and

decrement (subtract 1).The simplest binary operations are add, subtract, multiply, and divide.

Logical Operation (逻辑运算) The simplest logical unary operation is the NOT operation.

The simplest logical binary operations are AND, OR, and XOR.

ARITHMETIC LOGIC UNIT (ALU)

Page 11: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

ARITHMETIC OPERATIONS ON INTEGERS• Addition in Two’s Complement Adding numbers in two’ s complement is like adding the

numbers in decimal; you add column by column, and if there is a carry, it is added to the next column. When you add 2 bits, the result is 0 or 1.

Number of 1sNumber of 1s------------

NoneOneTwo

Three

ResultResult------------

0101

CarryCarry------------

11

Carry: 进位

Page 12: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Add two numbers in two’s complement representation: (+17) + (+22) (+39)

Carry 1

0 0 0 1 0 0 0 1 ++0 0 0 1 0 1 1 0

-------------------------------------Result 0 0 1 0 0 1 1 1 39

SolutionSolution

Example 1Example 1

Page 13: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Add two numbers in two’s complement representation: (+24) + (-17) (+7)

Carry 1 1 1 1 1

0 0 0 1 1 0 0 0 ++1 1 1 0 1 1 1 1

-------------------------------------Result 0 0 0 0 0 1 1 1 +7

SolutionSolution

Example 2Example 2

Page 14: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Add two numbers in two’s complement representation: (+127) + (+3) (+130)

Carry 1 1 1 1 1 1 1

0 1 1 1 1 1 1 1 ++ 0 0 0 0 0 0 1 1

----------------------------------Result 1 0 0 0 0 0 1 0 -126-126(Error)(Error)

An overflow has occurred.An overflow has occurred.

SolutionSolution

Example 4Example 4

Page 15: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Overflow(溢出) Overflow is an error that occurs when you try to store a

number that is not within the range defined by the allocation. When you add numbers in two’s complement using N bits, make sure that each number and the result are in the range defined for two’s complement representation.

Range of numbers in two’s complementrepresentation

- (2N-1) ---------- 0 ----------- +(2N-1 –1)

When you do arithmetic operations onnumbers in a computer, remember thateach number and the result should be

in the range defined by the bit allocation.

Page 16: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Subtraction in Two’s Complement

One of the advantages of two’s complement representation is that there is no difference between addition and subtraction. To subtract, negate (two’s complement) the second number and add. In other words, the following two statements are the same:

Number 1 – Number 2 Number 1 + (-Number 2)

Page 17: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Subtract 62 from 101 in two’s complement:

(+101) - (+62) (+101) + (-62)

Carry 1 1

0 1 1 0 0 1 0 1 ++1 1 0 0 0 0 1 0

----------------------------------Result 0 0 1 0 0 1 1 1 39The leftmost carry is discarded.

SolutionSolution

Example 5Example 5

Page 18: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

LOGICAL OPERATIONS (逻辑运算)

A single bit can be either 0 or1.You can interpret 0 as the logical value false and 1 as the logical value true.

A logical operation can accept 1 or 2 bits to create only 1 bit. If the operation is applied to only one input, it is a unary operation, if it is applied to 2 bits, it is a binary operation.

We will discuss one unary operator (NOT) and three binary operators (AND, OR, XOR).

unary operation : 一元运算binary operation :二元运算

Page 19: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

TRUTH TABLES(真值表) One way to show the result of a logical operation is with a

truth table. A truth table lists all the possible input combinations with the corresponding output.

Page 20: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

UNARY OPERATOR NOT Operator

The NOT operator has one input (a bit pattern). It inverts bits; that is, it changes 0 to1 and 1 to 0.

Use the NOT operator on the bit pattern 10011000.

Target Target 1 0 0 1 1 0 0 01 0 0 1 1 0 0 0 NOTNOT ------------------ ------------------Result Result 0 1 1 0 0 1 1 10 1 1 0 0 1 1 1

SolutionSolution

Example 7Example 7

NOT :“非”

Page 21: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

BINARY OPERATORS AND Operator

It takes two inputs (two bit patterns) and creates one output (bit pattern). For each pair of input bits, the result is 1 if and only if both bits are 1; otherwise, it is 0.

Use the AND operator on bit patterns 10011000 and 00110101.

Target Target 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 ANDAND 0 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 ------------------ ------------------Result 0 0 0 1 0 0 0 0Result 0 0 0 1 0 0 0 0

SolutionSolution

Example 8Example 8

AND:“与”

Page 22: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

OR Operator

It takes two inputs (two bit patterns) and creates one output (bit pattern). For each pair of input bits, the result is 0 if and only if both bits are 0; otherwise, it is 1.

Use the OR operator on bit patterns 10011000 and 00110101.

Target Target 1 0 0 1 1 0 0 01 0 0 1 1 0 0 0 OROR 0 0 1 1 0 1 0 10 0 1 1 0 1 0 1 --------------------------------------Result Result 1 0 1 1 1 1 0 11 0 1 1 1 1 0 1

SolutionSolution

Example 9Example 9

OR:“或”

Page 23: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

XOR Operator

It takes two inputs (two bit patterns) and creates one output (bit pattern). For each pair of input bits, the result is 0 if and only if both bits are equal; otherwise, it is 1.

Use the XOR operator on bit patterns 10011000 and 00110101.

Target Target 1 0 0 1 1 0 0 01 0 0 1 1 0 0 0 XORXOR 0 0 1 1 0 1 0 10 0 1 1 0 1 0 1 --------------------------------------Result Result 1 0 1 0 1 1 0 11 0 1 0 1 1 0 1

SolutionSolution

Example 10Example 10

XOR:“异或”

Page 24: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

APPLICATIONS The three logical binary operations can be used to modify

a bit pattern. They can unset, set, or reverse specific bits. The bit pattern to be modified is ANDed, ORed, or XORed with a second bit pattern, which is called the mask. The mask is used to modify another bit pattern.

unset :复位set :置位reverse :取反mask :掩码

Page 25: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Unsetting Specific Bits One of the applications of the AND operator is to unset (force

to 0) specific bits in a bit pattern. To do so, use an unsetting mask with the same bit length.

The rules for constructing an unsetting mask can be summarized as follows:

1. To unset a bit in the target bit pattern, use 0 for the corresponding bit in the mask.

2. To leave a bit in the target bit pattern unchanged, use 1 for the corresponding bit in the mask.

Page 26: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Use a mask to unset (clear) the 5 leftmost bits of a pattern. Test the mask with the pattern 10100110.

The mask is The mask is 0000011100000111..

Target Target 1 0 1 0 0 1 1 01 0 1 0 0 1 1 0 ANDANDMask Mask 0 0 0 0 0 1 1 10 0 0 0 0 1 1 1 --------------------------------------Result Result 0 0 0 0 0 1 1 00 0 0 0 0 1 1 0

SolutionSolution

Example 11Example 11

Page 27: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Setting Specific Bits One of the applications of the OR operator is to set (Force to 1)

specific bits in a bit pattern. To do so, use a setting mask with the same bit length.

The rules for constructing a setting mask can be summarized as follows:

1. To set a bit in the target pattern, use 1 for the corresponding bit in the mask.

2. To leave a bit in the target bit pattern unchanged, use 0 for the corresponding bit in the mask.

Page 28: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Use a mask to set the 5 leftmost bits of a pattern. Test the mask with the pattern 10100110.

The mask is The mask is 1111111111000.000.

Target Target 1 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 ORORMask 1 1 1 1 1Mask 1 1 1 1 1 0 0 0 0 0 0 ------------------------------------ResultResult 1 1 1 1 11 1 1 1 1 1 1 01 1 0

SolutionSolution

Example 13Example 13

Page 29: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Flipping Specific Bits One of the applications of XOR is to flip bits, which means to

change the value of specific bits from 0s to 1s, and vice versa. The rules for constructing an XOR mask can be summarized

as follows: 1. To flip a bit in the target bit pattern, use 1 for the

corresponding bit in the mask. 2.To leave a bit in the target bit pattern unchanged, use 0 for

the corresponding bit in the mask.

flip :翻转

Page 30: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Use a mask to flip the 5 leftmost bits of a pattern. Test the mask with the pattern 10100110.

Target Target 1 0 1 0 0 1 1 01 0 1 0 0 1 1 0 XORXOR Mask Mask 1 1 1 1 11 1 1 1 1 0 0 0 0 0 0 ------------------- -------------------Result Result 0 1 0 1 10 1 0 1 1 1 1 0 1 1 0

SolutionSolution

Example 15Example 15

Page 31: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

SHIFT OPERATIONS

Another common operation on bit patterns is the shift operation. A bit pattern can be shifted to the right or to the left. The right-shift operation discards the rightmost bit, shift every bit to the right, and inserts 0 as the leftmost bit. The left-shift operation discards the leftmost bit, shifts every bit to the left, and inserts 0 as the rightmost bit.

Shift operations can only be used when a pattern represents an unsigned number.

shift operation :移位运算

Page 32: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

If a bit pattern represents an unsigned number, a right-shift operation divides the number by two. The pattern 00111011 represents 59. When you shift the number to the right, you get 00011101, which is 29. If you shift the original number to the left, you get 01110110, which is 118.

Show how you can divide or multiply a number by 2 using shift operations.

SolutionSolution

Example 16Example 16

Page 33: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

MAIN MEMORY • Main memory is another subsystem in a computer. It is a

collection of storage locations, each with a unique identifier called the address.

• Data are transferred to and from memory in groups of bits called words. A word can be a group of 8 bits, 16 bits, 32 bits, or sometimes 64 bits. If the word is 8 bits, it is referred to as a byte. The term byte is so common in computer science that sometimes a 16-bit word is referred to as a 2-byte word or a 32-bit word is referred to as a 4-byte word.

main memory :主存储器,内存address :地址word :字

Page 34: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Main memory

Page 35: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

To access a word in memory requires an identifier. The total number of uniquely identifiable locations in memory is called the address space.

ADDRESS SPACE (地址空间)

UnitUnit------------

Kilobyte (K)Megabyte (M)Gigabyte (G)Terabyte (T)Petabyte (P)Exabyte (E)

Exact Number of bytesExact Number of bytes------------------------

210 bytes220 bytes230 bytes240 bytes250 bytes260 bytes

ApproximationApproximation------------103 bytes106 bytes109 bytes1012 bytes1015 bytes1018 bytes

Kilobyte :千字节, 1024 字节Megabyte :兆字节Gigabyte :十亿字节Terabyte : 1000 吉 [ 千兆 ] 字节 [GB] ;兆兆位

Page 36: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Address is represented as a bit pattern. If a computer has 64 kilobytes (216= 26× 210) of memory with a word size of 1 byte, then to define an address, you need a bit pattern of 16 bits. – The first location is referred to as address 0000000000000000

(address 0)– The last location is referred to as address

1111111111111111 (address 65535)

In general, if a computer has N words of memory, you need an unsigned of size log2 N bits to refer to each memory location.

Address as Bit Pattern

Memory addresses are defined usingunsigned binary integers.

Page 37: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

A computer has 32 MB (megabytes) of memory. How many bits are needed to address any single byte in memory?

The memory address space is 32 MB, or 2The memory address space is 32 MB, or 22525 (2 (255 x 2x 22020). This means you need). This means you needloglog22 2 22525 or 25 bits, to address each byte. or 25 bits, to address each byte.

SolutionSolution

Example 1Example 1

Page 38: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

A computer has 128 MB of memory. Each word in this computer is 8 bytes. How many bits are needed to address any single word in memory?

The memory address space is 128 MB, which The memory address space is 128 MB, which means 2means 22727. However, each word is 8 (2. However, each word is 8 (233) bytes, ) bytes, which means that you have 2which means that you have 22424 words. This words. This means you need logmeans you need log22 2 22424 or 24 bits, to address or 24 bits, to address

each word.each word.

SolutionSolution

Example 2Example 2

Page 39: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Two types of memory are available: RAM and ROM.

RAM (随机存储器)

Random access memory (RAM) makes up most main memory in a computer. The user can write something to RAM and later erase it simply by overwriting it. Another characteristic of RAM is that it is volatile; the information (program or data) is erased if the system is powered down.

Static RAM (SRAM): uses the traditional flip-flop gates to hold data; there is no need for refreshing; SRAM is fast but expensive.

Dynamic RAM(DRAM): uses capacitors; memory cells need to be refreshed periodically; DRAM is slow but inexpensive.

MEMORY TYPES

volatile :易失性SRAM :静态 RAMDRAM :动态 RAM

flip-flop gates :触发门电路capacitor :电容器refresh :刷新

Page 40: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

ROM (只读存储器) The contents of read-only memory (ROM) are written by the

manufacturer; the user is allowed to read but not write to ROM. Its advantage is that it is nonvolatile; its contents are not erased if you turn off the computer. Normally, it is used for programs or data that must not be erased or changed even if you turn off the computer.

Three types of ROM are introduced:

PROM (programmable read-only memory)

EPROM (erasable programmable read-only memory)

EEPROM (electronically erasable programmable read-only memory)

nonvolatile :非易失性

Page 41: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Use a very small amount of high-speed memory where speed is crucial. The registers inside the CPU are of this kind.

• Use a moderate amount of medium-speed memory to store data that are accessed often. Cache memory is of this kind.

• Use a large amount of low-speed memory for data that are not accessed very often. Main memory is of this kind.

MEMORY HIERARCHY 分级存储器体系

cache memory :高速缓冲存储器

Page 42: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

CACHE MEMORY Cache memory is faster than main memory but slower than the CPU

and the registers inside the CPU. Cache memory, which is normally small in size, is placed between the CPU and main memory.

高速缓冲存储器

Page 43: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

CONNECTING CPU AND MEMORY

The CPU and memory are normally connected by three groups of wires, each called a bus: data bus, address bus, and control bus .

bus :总线data bus :数据总线address bus :地址总线control bus :控制总线

Page 44: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Data Bus (数据总线)The number of wires depends on the size of the word. If the word is 32 bits (4 bytes) in a computer, you need a data bus with 32 wires so that all 32 bits of a word can be transmitted at the same time.

• Address Bus (地址总线)The number of wires in the address bus depends on the address space of memory. If the memory has 2n words, the address bus needs to carry n bits at a time. Therefore, it must have n wires.

• Control Bus (控制总线)The number of wires used in the control bus depends on the total number of control commands a computer needs.

Page 45: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

PROGRAM EXECUTION (程序执行) MACHINE CYCLE The CPU uses

repeating machine cycles to execute instructions in the program, one by one, from beginning to end. A simplified cycle can consist of three steps: fetch, decode, and execute .MACHINE CYCLE :机器周期fetch :取指decode :解码execute :执行

Page 46: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Contents of memory and register before execution

EXAMPLE

Page 47: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 48: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 49: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• 指令系统 , instruction set architecture– 指令系统是指 CPU 能执行的各种指令的集合– 计算机的机器指令由若干个字节组成 , 通常包含两部分内容:指

令操作码字段 , 操作数字段– 指令的一般格式为:

• 常见的指令系统– CISC(Complex Instruction Set Computer) 复杂指令集计算机

Intel x86, AMD

Motorola 68000

System/360, VAX, PDP-11– RISC(Reduced Instruction Set Computer) 精简指令集计算机

PowerPC

SPARC

Alpha

ARM

MIPS

Page 50: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

INPUT/OUTPUT (输入 /输出)The input/output (I/O) subsystem allows a computer to communicate with the outside world and to store programs and data even when the power is off. Input/output devices can be divided into two broad categories: nonstorage and storage devices.

NONSTORAGE DEVICES ( 非存储式设备)keyboard (键盘) ; mouse (鼠标) ; monitor (监视器) ; printer (打印机)

Page 51: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 52: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 53: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Data Communication Rates (数据通信速率)

• The rate in which bits are transferred from one computing component to another is measured in bits per second (bps比特 / 秒 ).

• Common units include Kbps(kilo-bps, equal to 1000 bps), Mbps (mega-bps, equal to 1 million bps), and Gbps (giga--bps, equal to 1 billion bps).

• The maximum rate available in a particular case depends on the type of the communication path and the technology used in its implementation.

• two basic types of communication paths: parallel and serial – parallel communication ( 并 行 通 信 ) : several bits are

transferred at the same time, each on a separate line. – serial communication (串行通信) is based on transferring

only one bit at a time.

Page 54: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

STORAGE DEVICES (存储设备)

Storage devices can store large amounts of information to be retrieved at a later time. They are cheaper than main memory, and their contents are nonvolatile (not erased when the power is turned off). They are sometimes referred to as auxiliary storage devices. We categorize them as either magnetic or optical.

Magnetic Storage Devices (磁性存储设备) use magnetization to store bits of data.

Magnetic Disk (磁盘) A magnetic disk is one or more disks stacked on top each other. The disks are coated with a thin magnetic film. Information is stored on and retrieved from the surface of the disk using a read/write head for each magnetized surface of the disk.

Page 55: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Physical layout of a magnetic disk

Page 56: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Surface Organization

To organize data stored on the disk, each surface is divided into tracks (磁道) , and each track is divided into sectors (扇区) . The tracks are separated by an intertrack gap, and the sectors are separated by an intersector gap.

Page 57: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Data Access (数据存取) A magnetic disk is considered a random access (随机存取)

device. • Performance The performance of a disk depends on several factors :

– the rotational speed( 转动速度 )

– the seek time( 寻道时间 )

– the transfer time

Page 58: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Optical Storage Device (光存贮器) use light (laser) to store and retrieve data. The use of optical storage technology followed the invention of the CD (compact disc), used to store audio information. Today, the same technology (slightly improved) is used to store information in a computer. Devices that use this technology include CD-ROMs, CD-Rs, CD-RWs, and DVDs.

CD-ROM (Compact Read-Only Memory ) : (650MB)

CD-R (Compact Disc-Recordable): (650MB)

CD-RW (Compact Disc-Rewritable): (650MB)

DVD (Digital Versatile Disc/Digital Video Disc) :(4.7GB)

Page 59: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Speed

CD-ROM drives come in different speeds. Single speed is called 1x, double speed is called 2x, and so on. If the drive is single speed, it can read up to 153,600 bytes per second.

SpeedSpeed------------

1x2x4x6x8x12x16x24x32x40x

Data RateData Rate------------------------

153,600 bytes per second307,200 bytes per second614,400 bytes per second921,600 bytes per second1,228,800 bytes per second1,843,200 bytes per second

2,457,600 bytes per second3,688,400 bytes per second 4,915,200 bytes per second6,144,000 bytes per second

ApproximationApproximation------------150 KB/s300 KB/s600 KB/s900 KB/s1.2 MB/s1.8 MB/s2.4 MB/s3.6 MB/s4.8 MB/s6 MB/s

Page 60: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

CONNECTING I/O DEVICES

I/O devices cannot be connected directly to the buses that connect the CPU and memory. They are attached to the buses through what is called an input/output controller or interface (接口) . There is one specific controller for each input/output device.

• serial (串行): SCSI( The small computer system interface), USB( universal serial bus ),

FireWire( IEEE standard 1934, serial interface)• parallel (并行) : ISA, PCI

Page 61: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 62: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• USB ( Intel 公司开发的通用串行总线架构) Universal serial bus (USB) controller is a serial controller

used to connect slower devices such as the keyboard and mouse to a computer.

USB 1.1(12Mbps), 2.0(480Mbps) , USB 3.0 ( 5Gbps )

Page 63: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

ADDRESSING INPUT/OUTPUT DEVICES • Isolated I/O ; Memory-Mapped I/O• Isolated I/O (独立) In the isolated I/O method, the instructions used to read/write memory

are to totally different from the instructions used to read/write input/output devices. Each input/output device has its own address. The input/output addresses can overlap (重叠) with memory addresses.

ADDRESSING:寻址

Page 64: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• Memory-Mapped I/O (存储映像) In the memory-mapped I/O method, the CPU does not have

separate instructions for transferring data from memory or input/output devices, all the memory instructions can be used by the input/output devices. The disadvantage is that the part of the address space used for memory is allocated to the registers in the input/output controllers.

Page 65: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

• I/O 设备比 CPU 慢的多 , 因此 CPU 必须和 I/O 设备同步– 程序控制输入输出– 中断控制输入输出– 直接存储器存取 (Direct Memory Access, DMA)

Page 66: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 67: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 68: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 69: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

Page 70: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

相关课程• 数字逻辑• 计算机组成原理• 计算机系统结构• 计算机接口

Page 71: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

作业• 4-21——4-25• 4-53——4-58• 5-39——5-59

Page 72: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

You can perform arithmetic or logical operations on bits. Most computers use the two’s complement method of integer representation. If there is a carry after addition of the leftmost digits, the carry is discarded. To subtract in two’s complement, just negate the number to be subtracted and add. Numbers to be added must be within the range defined by the bit allocation. The term overflow describes a condition in which a number is not within the range defined by the bit allocation. Logical operation on bits can be unary (one input) or binary (two inputs). The unary NOT operator inverts its input.

SUMMARY

Page 73: Computer Organization Chapter 5 天津大学软件学院. 计算机导论 虚拟机, virtual machine 计算机系统由硬件 (Hardware) 和软件 (Software) 组成 传统机器级以上的所有机器都称为虚拟机,

计算机导论

The result of the binary AND operation is true only if both inputs are true. The result of the binary OR operation is false only if both inputs are false. The result of the binary XOR operation is false only if both inputs are the same. A mask is a bit pattern that is applied to a target bit pattern to achieve a specific result. To unset (clear) a bit in a target bit pattern, set the corresponding mask bit to 0 and use the AND operator. To set a bit in a target bit pattern, set the corresponding mask bit to 1 and use the OR operator. To flip a bit in a target bit pattern, set the corresponding mask bit to 1 and use the XOR operator.

SUMMARY (continued)