the central processing unit: what goes on inside the computer

58
中中中中中 (CPU) 電電電電電電電電電電 中中中

Upload: sammy17

Post on 14-Dec-2014

474 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: The Central Processing Unit: What Goes on Inside the Computer

中央處理器 (CPU)

電腦內部是怎麼運作的

第四章

Page 2: The Central Processing Unit: What Goes on Inside the Computer

學習目的學習目的 講解中央處理器的各個組成元件,說明他們彼此間如何運作以及與記憶體的溝通

描述電腦如何執行程式指令 解釋電腦如何表示資料 描述電腦如何找到指令和資料 講解微電腦系統單元上的主機板的各個元件 明瞭電腦處理速度的計量方式以及增加速度的方法

Page 3: The Central Processing Unit: What Goes on Inside the Computer

內容內容 CPUCPU 儲存體類型儲存體類型 執行程式執行程式 在記憶體中尋找資料在記憶體中尋找資料 系統單元系統單元 微處理器微處理器 半導體記憶體半導體記憶體 匯流排匯流排 速度和能力速度和能力

Page 4: The Central Processing Unit: What Goes on Inside the Computer

CPUCPU

Page 5: The Central Processing Unit: What Goes on Inside the Computer

CPUCPU

將資料轉換成資訊 控制中心 執行儲存在記憶體中程式指令的一組電路 分成兩個主要部分

• 控制單元 (CU)• 算術邏輯單元 (ALU)

Page 6: The Central Processing Unit: What Goes on Inside the Computer

控制單元控制單元 CU CU ((Control Unit)Control Unit)

硬體的一部分,負責控制 指示電腦系統執行程式指令 負責與硬體其它部分的溝通

Page 7: The Central Processing Unit: What Goes on Inside the Computer

算術邏輯單元算術邏輯單元ALUALU (Arithmetic / Logic Unit) (Arithmetic / Logic Unit)

負責執行算術運算動作

負責執行邏輯運算動作

Page 8: The Central Processing Unit: What Goes on Inside the Computer

算術運算算術運算

加法減法乘法除法

Page 9: The Central Processing Unit: What Goes on Inside the Computer

邏輯運算邏輯運算

評估條件值 進行比較 可以比較

• 數字• 字母• 特別字元

Page 10: The Central Processing Unit: What Goes on Inside the Computer

暫存器暫存器

各有特殊的用途速度快

是個暫時存放的地方 位於 CPU 中

指令暫存器儲存目前正在執行的指令

資料暫存器儲存正等著被處理的資料

儲存處理過後的結果

Page 11: The Central Processing Unit: What Goes on Inside the Computer

儲存體類型儲存體類型 輔助儲存體

• 儲存以後要用到的資料• 長期儲存

記憶體• 儲存最近要使用的資料• 暫時儲存• 存取速度比輔助儲存體快

暫存器• 儲存與目前正在執行的指令立即相關的資料• 存取速度記憶體快

Page 12: The Central Processing Unit: What Goes on Inside the Computer

儲存體容量的測量單位KB – kilobyte

• 1024 個位元組• 有些磁片• 快取記憶體

MB – megabyte• 約百萬個位元組• RAM

GB – gigabyte• 約十億個位元組• 硬碟• CD 和 DVD

TB – terabytes• 約一兆個位元組• 大型硬碟

Page 13: The Central Processing Unit: What Goes on Inside the Computer

記憶體記憶體它有許多名稱它有許多名稱

主要儲存體 (primary storage)Primary memory

Main storageInternal storage

主記憶體 (Main memory)

Page 14: The Central Processing Unit: What Goes on Inside the Computer

記憶體的主要類型記憶體的主要類型RAMRAM

隨機存取記憶體隨機存取記憶體((Random Access Memory)Random Access Memory)

ROMROM唯讀唯讀記憶體記憶體

(Read Only Memory)(Read Only Memory)

Page 15: The Central Processing Unit: What Goes on Inside the Computer

RAMRAM

需要電流才能保持資料 揮發性 (Volatile) 可以讀取及修改裡面的指令和資料 使用者通常是指這種記憶體

Page 16: The Central Processing Unit: What Goes on Inside the Computer

RAMRAM 裡有什麼裡有什麼 ??

作業系統 目前正在執行中的程式 上述程式需要的資料 等著要輸出的中間結果

Page 17: The Central Processing Unit: What Goes on Inside the Computer

ROMROM

非揮發性 (Non-volatile) 負責開機的指令 裡面的指令和資料可以讀取,但不能修改 這些指令通常是在工廠裡燒錄進去的

Page 18: The Central Processing Unit: What Goes on Inside the Computer

執行程式執行程式 CU 擷取指令放進記憶體中

CU 將此指令解碼 CU 通知硬體相關部分準備採取行動

將控制權轉移到硬體的相關部分

執行工作 控制權回到 CU

Page 19: The Central Processing Unit: What Goes on Inside the Computer

機器循環週期機器循環週期

I-time CU 從記憶體中擷取

(fetch) 指令,然後放進暫存器中

CU 將此指令解碼 (decode) ,並決定所需要的資料在記憶體中的位置

Page 20: The Central Processing Unit: What Goes on Inside the Computer

機器循環週期機器循環週期E-time 執行

• CU 將資料從記憶體搬移到 ALU 內的暫存器中

• 由 ALU 負責控制與執行指令• 控制權回到 CU

CU 將運算後的結果存放在記憶體或暫存器中

Page 21: The Central Processing Unit: What Goes on Inside the Computer

系統時鐘系統時鐘 系統時鐘以固定的速率製造脈波 每個脈波就是一個機器循環週期 一個程式指令可能是由一串給 CPU 的小指令所組成

每一個 CPU 指令至少必須要花一個脈波才能完成

每一種類型的 CPU 都有一組指令集 – 也就是它能了解與處理的指令

Page 22: The Central Processing Unit: What Goes on Inside the Computer

在記憶體中尋找資料在記憶體中尋找資料 記憶體中的每個位置都會被標示一個獨一無二的位址 (address)• 位址不會改變• 內容可能會改變

每個記憶體位置可以保存一條指令或一個資料 程式設計師會使用符號位址

Page 23: The Central Processing Unit: What Goes on Inside the Computer

資料表示法資料表示法開 開 // 關關 ((On/Off)On/Off)

使用二進位系統來表示電路的狀態

Page 24: The Central Processing Unit: What Goes on Inside the Computer

位元、位元組、字組位元、位元組、字組 位元 (BIT)

• Binary DigIT• 電路開或關 (On/off)• 1 或 0

位元組 (BYTE)• 8 個 bit• 每一個位元組可儲存一個字元

字組 (WORD)• 暫存器的大小• CPU 在處理時當做一個單位的位元個數

Page 25: The Central Processing Unit: What Goes on Inside the Computer

編碼機制編碼機制 ASCII

• 使用一個包含 8 個位元的位元組• 28 = 256 種可能的組合或字元• 用在幾乎所有的 PC 和許多較大型的電腦

EBCDIC• 使用一個包含 8 個位元的位元組• 28 =256 種可能的組合或字元• 主要用在 IBM 相容的大型主機

Unicode• 使用兩個包含 8 個位元的位元組 (16 個位元 )• 216 = 65,536 種可能的組合或字元• 可支援世界上所有語言所需要的字• 與 ASCII 回溯相容

Page 26: The Central Processing Unit: What Goes on Inside the Computer

系統單元系統單元黑盒子黑盒子

放置電腦元件• 主機板 • 儲存設備• 連線

有些 Apple Macintosh 電腦則是把系統單元放在螢幕外殼裡

Page 27: The Central Processing Unit: What Goes on Inside the Computer

系統單元系統單元黑盒子黑盒子

主機板包含 微處理器晶片 記憶體晶片 與其它硬體部分的連線 其它可能加入的晶片 – 如數學輔助處理器

Page 28: The Central Processing Unit: What Goes on Inside the Computer

系統單元系統單元黑盒子黑盒子儲存設備硬碟機軟碟機

CD-ROM 光碟機DVD-ROM光碟機

Page 29: The Central Processing Unit: What Goes on Inside the Computer

微處理器微處理器

CPU 是蝕刻在一個晶片上 晶片大小是 ¼ x ¼ 吋 由矽元素組成 包含數百萬個電晶體

• 它是可控制電流通過的電子閘門

Page 30: The Central Processing Unit: What Goes on Inside the Computer

微處理器的組成元件微處理器的組成元件

控制單元 – CU 算術邏輯單元 – ALU 暫存器 系統時鐘

Page 31: The Central Processing Unit: What Goes on Inside the Computer

發明出更好的微處理器發明出更好的微處理器 將整個電腦的電路放進一片微晶片中

•更便宜•更快

執行先前由其他硬體所負責的功能• 數學輔助處理器現在是微處理器的一部分• 多媒體指令現在也成了微處理器的一部分

Page 32: The Central Processing Unit: What Goes on Inside the Computer

發明出更好的微處理器發明出更好的微處理器

電腦跑得更快 造價更便宜 更穩定

合併到微處理器上的功能越多:

Page 33: The Central Processing Unit: What Goes on Inside the Computer

微處理器的種類微處理器的種類

IntelIntel PentiumPentium Celeron Celeron XeonXeon 和 ItaniumItanium

Intel 相容 Cyrix AMD

Page 34: The Central Processing Unit: What Goes on Inside the Computer

微處理器的種類微處理器的種類 PowerPC

• 由 Apple 、 IBM 和 Motorola 所合作設計• 主要是用在 Apple Macintosh 個人電腦家族上

• 它也可以用在伺服器與內嵌式系統中 Alpha

• 由 Compaq (康柏 ) 所製造• 用在高階伺服器與工作站上

Page 35: The Central Processing Unit: What Goes on Inside the Computer

半導體記憶體半導體記憶體 可靠度高可靠度高 體積小體積小 低價位低價位 低功率低功率 可大量製造符合經濟效益可大量製造符合經濟效益 揮發性揮發性 MonolithicMonolithic

• 晶片上的所有電路構成了一個不可分割的儲存單晶片上的所有電路構成了一個不可分割的儲存單元元

Page 36: The Central Processing Unit: What Goes on Inside the Computer

半導體記憶體半導體記憶體CMOSCMOS

互補金氧半導體 (Complementary metal oxide semiconductor)

只耗用一點點電力 用在 PC 上儲存電腦在開機過程所需要的硬體設定資訊

藉由電池的電力使它在電腦關機後仍然保存著資料

Page 37: The Central Processing Unit: What Goes on Inside the Computer

RAMRAM

保存目前執行中程式的指令與資料 在記憶體裡的資料可以被隨機存取 存取方便且快速 揮發性 電源關閉後 RAM 上的資料就會消失 RAM 上的資料可以被修改

Page 38: The Central Processing Unit: What Goes on Inside the Computer

RAM RAM 的種類的種類

SRAMSRAM 只要有電力,儲存內容就會依舊存在 速度比 DRAM 快

Page 39: The Central Processing Unit: What Goes on Inside the Computer

RAM RAM 的種類的種類

DRAM 必須持續充電 因為它的體積與價格的優勢,大多數的 PC 記憶體都使用它

SDRAM • 比較快的一種 DRAM

Rambus DRAM• 速度比 SDRAM 快• 價格較貴

Page 40: The Central Processing Unit: What Goes on Inside the Computer

擴充擴充 RAMRAM

購買封裝在電路板上的記憶體模組 SIMM – 晶片是安裝在電路板的一邊 DIMM – 晶片是安裝在電路板的兩邊 你能安裝的 RAM 數量最多是多少,取決於主機板的設計

Page 41: The Central Processing Unit: What Goes on Inside the Computer

ROMROM

在工廠製造時便燒錄了永久的程式和資料 可以被讀取 可以被使用 使用者不能修改 儲存電腦開機時所需要啟動的開機程序 非揮發性

Page 42: The Central Processing Unit: What Goes on Inside the Computer

PROMPROM

可程式化 (Programmable) ROM ROM 燒錄器 (ROM burner) 可以修改某些特殊 ROM 晶片上的指令

Page 43: The Central Processing Unit: What Goes on Inside the Computer

系統匯流排系統匯流排

一組傳送電子訊號的電路 系統匯流排

• 負責在 CPU 與記憶體之間傳送資料 匯流排寬度

• 電腦一次可以傳輸的資料位元數• 通常會和 CPU 的字組 (word) 大小一致

速度是用 megahertz (MHz) 來衡量

Page 44: The Central Processing Unit: What Goes on Inside the Computer

系統匯流排系統匯流排

CPUCPU 可以支援較大的數字精確度以及更多種可以支援較大的數字精確度以及更多種類的指令類的指令

CPUCPU 可以支援較大的數字精確度以及更多種可以支援較大的數字精確度以及更多種類的指令類的指令

匯流排寬度越大 = 電腦的運算能力越強

CPU 一次可以傳輸更多的資料 = 電腦速度變快

CPU 能參考到更大的記憶體位址 = 有更多的記憶體

Page 45: The Central Processing Unit: What Goes on Inside the Computer

擴充匯流排擴充匯流排 連接到擴充槽 將擴充電路板插入擴充槽裡

•介面卡 (interface card)• adapter card

提供外部的連接端 / 連接埠•序列埠•平行埠

Page 46: The Central Processing Unit: What Goes on Inside the Computer

擴充匯流排擴充匯流排

Page 47: The Central Processing Unit: What Goes on Inside the Computer

PC PC 匯流排與連接埠匯流排與連接埠ISAISA 用在慢速的裝置如滑鼠和數據機上PCIPCI 適用於連接高速的裝置如硬碟和網路卡上AGPAGP 連接記憶體與圖形卡以提供更快速的視訊效能USBUSB 支援 “ daisy-chaining” 功能,省去需要多

張擴充卡的麻煩;可以“熱切換” (hot-swappable)

IEEE IEEE 1394 1394 (FireWire(FireWire))

一種高速的匯流排,通常是用在連接視訊設備到你的電腦上

PC CardPC Card 信用卡般大小的 PC Card 裝置,通常是用在筆記型電腦上

Page 48: The Central Processing Unit: What Goes on Inside the Computer

速度和運算能力速度和運算能力

是什麼因素讓某台電腦比其他電腦更快呢? 微處理器的速度 匯流排的大小 有沒有快取 (cache) 快閃記憶體 RISC 電腦 平行處理

Page 49: The Central Processing Unit: What Goes on Inside the Computer

電腦運算速度電腦運算速度

完成指令執行所需要的時間

千分之一秒 (Millisecond) 百萬分之一秒 (Microsecond) 十億分之一秒 (Nanosecond)

• 目前新型的電腦 兆分之一秒 (Picosecond)

•未來的電腦

Page 50: The Central Processing Unit: What Goes on Inside the Computer

微處理器的速度微處理器的速度 時鐘速度

• 百萬赫茲 (Megahertz , MHz) • 十億赫茲 (Gigahertz , GHz)

每秒完成的指令個數• 每秒一百萬個指令 (MIPS)

電腦處理複雜數學計算的能力• 每秒一百萬個浮點運算 (Megaflop)

Page 51: The Central Processing Unit: What Goes on Inside the Computer

快取快取 (Cache)(Cache)

它是一塊小但非常快速的暫存記憶體 目的為了加速內部資料和軟體指令的傳輸 存放著最近用過或最常被使用到的資料和指令

Page 52: The Central Processing Unit: What Goes on Inside the Computer

快取快取 (Cache)(Cache)

第 1 步處理器要求擷取資料或指令

第 2 步到主記憶體中的該位址去

讀取

第 3 步傳送到 CPU 和快取中

下一次微處理器需要資料或指令時•先到記憶體快取中尋找• 找不到再到記憶體中尋找

處理器

R

A

M

快取

Page 53: The Central Processing Unit: What Goes on Inside the Computer

快取的種類快取的種類 內部快取

• 第一級 (L1)• 內建在微處理器中• 最多到 128KB

外部快取• 第二級 (L2)• 在單獨晶片上• 256KB 或 512 KB• SRAM 技術• 它比 L1 快取便宜但是較慢• 比記憶體快但是較貴

Page 54: The Central Processing Unit: What Goes on Inside the Computer

快閃記憶體快閃記憶體 非揮發性 RAM 使用在

• 行動電話• 數位相機• 數位錄音器• PDA

Page 55: The Central Processing Unit: What Goes on Inside the Computer

指令集指令集 CISC 技術

• 複雜指令集計算模式• 一般傳統電腦• 其中許多指令很少用到

RISC 技術• 精簡指令集計算模式• 只提供一小組指令• 速度增快• 適合很少用到複雜指令的程式

繪圖領域 工程領域

Page 56: The Central Processing Unit: What Goes on Inside the Computer

運算處理的種類運算處理的種類

循序處理• 每次只執行一項指令• 擷取、解碼、執行、儲存

平行處理•同一時間有多個處理器同時工作• 有能力處理每秒鐘數兆個浮點數運算指令•例如網路伺服器與超級電腦

Page 57: The Central Processing Unit: What Goes on Inside the Computer

運算處理的種類運算處理的種類

管線技術 (Pipelining)• 指令的動作並不需要在下一個指令開始運作前完成• 例如指令 1 完成擷取動作開始解碼後,就可以開始擷取指令 2

Page 58: The Central Processing Unit: What Goes on Inside the Computer