電腦的基本運作原理 丁培毅 速成版 / 概念版
功能與速度日勝一日的電腦 手機 車用電腦, 導航機 筆記型電腦 個人電腦 網路伺服器 雲端運算系統 超級電腦 2/45
無遠弗界的通訊數據網路 網際網路 3G, 3.5G, 3.75G, 4G 網路 無線網路 (WiMAX, WiFi, Bluetooth) 物聯網 3/45
數位化的資料表示方式 需要先以適當的方法表示資料, 電腦才能快速地 大量地處理資料 記錄資料 資料包括 數字 :, -23, -2.45, 2.3 25, 2, 文字 : a,y,z,b,r,%,#,,,č,, 中, あ, 위, 顏色 : 圖片 : 照片 : 4/45
資料表示 (cont d) 視訊 : 聲音 : 5/45
電腦硬體如何表示 與 磁性物質 : 磁極方向, 磁片, 磁碟, 磁帶 光學物質 : 反射 / 透射, CD/DVD/BlueRay 電位差 : 有 / 無, 電容, DRAM 電流 : 有 / 無, 方向, 電流開關 量子現象 : 量子井中是否有電子, NAND flash, SSD, 記憶卡 電腦為何要運用 - 二進位方式表示所有資料? 6/45
資料表示 (cont d) 數字 : 十進位系統 ( 我們每天在使用 ) 使用的符號 :,, 2, 3, 4, 5, 6, 7, 8, 9, +, 整數 : 2345 = 4 + 2 3 + 3 2 + 4 + 5 負數 : 5432 小數 : 2.34 = + 2 + 3 - + 4-2 二進位系統 ( 電腦硬體在使用的 ) 使用的符號 :, 整數 : = 2 3 + 2 2 + 2 + 2 = (3) 負數 : ( +) 2 = ( ) (5 位數, 二的補數表示法 ) 小數 :. = 2 + 2 + 2 - + 2-2 = (3.25) ( 定點表示法 ) 7/45
二進位與十進位的轉換 (.) 2 (26.65625) 2 4 + 2 3 + 2 + 2 - + 2-3 + 2-5 = (26.65625) (234.5625) (.) 2 2 234 67 38 54 77 38 9 9 4 2.5625.25.25.5. 2 8/45
二的補數表示法 表示負數 : 以 4 個位元為例 正整數 B 的二進位表示法 B 的十進位數值 b 3 b 2 b b, b 3 = b 2 2 2 + b 2 + b e.g. 3 二的進十位進對位應值 7 6 5 4 四補位數元表二示的法 二的的十補進數位對應 7 6 5 4 -B 的二的補數表示法等效的十進位數值 2 4 (b 2 2 2 + b 2 + b ) 6-3=3 3 2 3 2 -B 的二的補數表示法 c 3 c 2 c c, c 3 = 2 4 (b 2 2 2 + b 2 + b ) = 2 2 + c 2 2 2 + c 2 + c 目的 : 使用加法的硬體來完成減法 4 3-2 -3 5 - a 2 a a b 2 b b = a 2 a a + ( b 2 b b ) 2-4 -5 = a 2 a a + c 2 c c 9-6 -7 = (a 2 2 2 + a 2 + a ) + (2 4 (b 2 2 2 + b 2 + b )) 8-8 9/45
二進位資料的運算 加法 ( 減法 ) (+88) + (+25) ------------------------ (+3) 溢位 (Overflow) 8-bit Signed number addition (+72) + (+57) -------------------------- (+29) AND/OR/XOR (A) (B) -------------- (A AND B) (A OR B) (A XOR B) 反向溢位 (Underflow) 8-bit Signed number addition (-27) + ( -6) -------------------------- (-33) /45
二進位的 浮點 表示法 科學記號 十進位 2.3 25 二進位. 2 4 IEEE 754 Single Precision 正負號指數小數 4. /45
十六進位 一長串的二進位數字人很難快速正確地記錄下來, 例如 : ( ) 2 用十進位來表示會比較容易, 例如 : (27929) 可是和二進位之間的轉換比較沒那麼直覺 用十六進位的話轉換和記錄都沒有問題 : (6D9) 6 Binary Dec Hex Binary Dec Hex Binary Dec Hex Binary Dec Hex 4 4 8 8 2 C 5 5 9 9 3 D 2 2 6 6 A 4 E 3 3 7 7 B 5 F 2/45
文字的表示方法 ASCII 內碼表 2 3 4 5 6 7 8 9 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DCL DC2 DC3 2 DC4 NAK SYN ETB CAN EM SUB ESC FS GS 3 RS US SP! " # $ % & ' 4 ( ) * +, -. / 5 2 3 4 5 6 7 8 9 : ; 6 < = >? @ A B C D E 7 F G H I J K L M N O 8 P Q R S T U V W X Y 9 Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w 2 x y z { } ~ DEL 3/45
文字的表示方法 (cont d) Big5 中文編碼方式 : 雙位元組,35 繁體字例如 : 中文字 A4A4 A4E5 A672 GB 簡體中文編碼方式 : 雙位元組,6763 簡體字例如 : 中文字 D6D CEC4 D7D6 Unicode 編碼方式 : UTF-8, UTF-6 例如 UTF-8: 中文字 E4B8AD E69687 E5AD97 UTF-6: 中文字 2D4E 8765 575B 4/45
色彩, 圖片, 影像, 與視訊 色彩 : 三原色 : 紅, 綠, 藍每一個顏色用一個 到 255 的整數表示其光線強度 圖片 影像 : 以點陣圖 ( 矩陣 ) 的方式記錄每一個點的顏色 視訊 : 基本上可以看成是一連串的圖片 5/45
聲音 以數字週期性的記錄聲音訊號裡振幅的變化 取樣週期取決於聲音內容的頻寬, 越高頻的聲音需要比較短的取樣週期以避免失真.7 7.9 5.3 5.5 3.4 6/45
電晶體 (transistor) 如何運作? 手動開關 手動控制斷路 / 通路 電子開關 數位電路中運作在飽和區的金屬氧化物半導體場效電晶體 (MOSFET) 以接在 Gate 上的電壓控制斷路 / 通路 7/45
8/45 電晶體 邏輯閘 NOT 邏輯閘 NAND 邏輯閘 X X V cc X X AND 邏輯閘 Z Y X Z Y X X X X Y Z X Y Z V cc X Z Y X Z Y V cc Z
9/45 邏輯閘 (cont d) OR 邏輯閘 Z Y X V cc X Z Y Z NOR 邏輯閘 XOR 邏輯閘 V cc X Z Y Z Y X Z X Y Z X Y Z X Y Z Y X Z XY XY X Y XY XY XYY XXY X Y Z A = A A + B = A B A B = AB B
2/45 加法電路 將位元 A 與位元 B 相加 C(arry) S(um) B A Half Adder S C A B AB C B A AB AB S A B Sum Carry A Sum Carry B A B C S + + +
加法電路 (cont d) + B + + + 將位元 A 與位元 B 相加, C out S 並且加上右邊位元和的 A B C 進位 C in A B S(um) C out in S S Cin A B C AB C (A B) out in H.A. C out Full Adder S H.A. C in A B C in C in A C out 2/45
加法電路 (cont d) 使用 NAND 邏輯閘設計的等效電路 A S B C in C out 將兩個四位元數字 a 3 a 2 a a 與 b 3 b 2 b b 相加得到四位元數字 s 3 s 2 s s 及進位位元 c 4 a 3 b 3 a 2 b 2 a b a b c 4 Full Adder c 3 Full Adder c 2 Full Adder c Full Adder c = s 3 s 2 s s 22/45
減法 b 3 b 2 b b Subtract a 3 a 2 a a A B A B A B A B c 4 C out Full Adder C in C out Full Adder C in C out Full Adder C in C out Full Adder C in S S S S s 3 s 2 s s A B = A + (-B) 計算 B 的二的補數 (2 s complement) 即為 -B 用加法電路把 A 和 -B 兩個數字加總起來 23/45
加法電路 (cont d) CMOS Full Adder 24/45
Intel Core i7-86 Lynnfield CPU Quad-core Codename Lynnfield 45nm Nehalem micro-architecture, 29 25/45
Moore s Law size Silicon atom diameter =.234 nm nm 25 7nm 5nm 3nm 26/45
基本的電腦模型 處理器 (Central Processing Unit, Microprocessor) data Register Register Arithmetic & Logic Unit address Input/ Output clock Register 5 Control Unit & Instruction Register Program Counter Main Memory 主記憶體 27/45
Stored Program von Neumann Architecture 28/45
29/45
匯流排 ( 位址, 資料, 與控制 ) Data bus Address bus Control bus CPU RAM I/O 3/45
3/45
指令執行週期 (Instruction Cycles) control unit decode arithmetic / logic execute unit Parallel processing with pipeline RAM fetch (store) pipe pipe2 fetch execute decode execute fetch fetch decode execute A 3 GHz CPU has 3 9 clock cycles per second pipe3 decode execute fetch decode Each phase might take a few clock cycles clock cycle clock cycle2 clock cycle3 clock cycle4 32/45
CPU 執行的三大類指令 資料移轉 (Data transfer instructions): e.g. mov, xchg, store, load between registers and memories (I/O) 算術運算 (Arithmetic instructions): e.g. add, sub, inc, dec, mul, imul, div, idiv 邏輯運算及程式流程控制 (Logical and program control instructions): e.g. and, or, xor, not, jmp, call, je, jne, jnc, jno, loop, ret, 33/45
CPU 執行 mov @AF, R 指令 Program Counter 記錄目前 CPU 執行到的指令的記憶體位址 由記憶體中將 mov @AF, R 指令取出置於 Instruction Register 指令中的記憶體位址 AF 為資料搬移指令 mov 的資料目的地 指令中的 R 為資料搬移指令 mov 的資料來源 透過資料匯流排搬移資料 data Register Register Arithmetic & Logic Unit address Input/ Output Register 5 Control Unit & Instruction Register Program Counter Main Memory 主記憶體 34/45
CPU 執行 add R, R 指令 Program Counter 記錄目前 CPU 執行到的指令的記憶體位址 由記憶體中將 add R, R 指令取出置於 Instruction Register 指定加法線路由 R 及 R 取得輸入資料 將 R + R 的結果放回 R data Register Register + Arithmetic & Logic Unit address Input/ Output Register 5 Control Unit & Instruction Register Program Counter Main Memory 主記憶體 35/45
CPU 執行 jmp @B 指令 Program Counter 記錄目前 CPU 執行到的指令的記憶體位址 由記憶體中將 JMP @B 指令取出置於 Instruction Register 將 B 由 Instruction Register 中移入 Program Counter data Register Register Arithmetic & Logic Unit address Input/ Output Register 5 Control Unit & Instruction Register Program Counter Main Memory 主記憶體 36/45
Leaps in Technology 3bit NAND flash MLC, electrons in 2nm width quantum well 37/45
Leaps in Technology A 982 Osborne Executive portable computer, with a Zilog Z8 4MHz CPU vs. a 27 Apple iphone with a 42MHz ARM CPU weighs times, 5 times volume, cost times, and /th clock rate 38/45
Early Computers Enigma Cipher, 94 - Alan Turing s Bombe, 94 Colossus Mark II, 943 39/45
Early Computers (cont d) NASA guidance computers Apollo 4 Guidance Computer, 968 Gemini Guidance Computer, 965 4/45
Early Computers (cont d) Main Frames ENIAC accumulators, 942 UNIVAC, 95 IBM System/36, 964 4/45
Early Computers (cont d) Mini-computers VAX-/78, 977 PDP-, 97 42/45
Early Computers (cont d) IBM PC-XT, 98 Apple II, 977 Personal computers Lisa, 983 Macintosh, 984 43/45
Early Computers (cont d) Workstations Next Cube, 99 Sun Sparc, 99 SGI Octane, 997 IBM RS/6, 99 44/45
Nowadays Top Computers Super-Computers Climate change computing NASA s SGI Cray Super-computers D-Wave Quantum computers Google and NASA 45/45