Chapter II 軟硬之間 電腦的程式與硬體 1
資料的二進位表示法 資訊在電腦外部及內部表示法上的不同 2
資料的二進位表示法 二進位與十進位轉換表 3
資料的二進位表示法 1035 0000010000001011-1035 直接符號 1000010000001011 1 s 補數 1111101111110100 2 s 補數 1111101111110101 負整數表示法 4
資料的二進位表示法 浮點數表示法 5
資料的二進位表示法 字元 ( 文字 ) 對應到二進位數編碼 ASCII code ( 美國國家資訊交換標準碼 )set 8 bits per character; 256 character codes UNICODE code ( 萬國碼 )set 16 bits per character; 65,536 character codes 字串是由字元以某種編碼方式所組成的 6
Keyboard: C ASCII Code: 67 Binary: 01000011 ASCII 碼轉換表 7
資料的二進位表示法 http://www.unicode.org/ http://www.unicode.org/standard/translations/t-chinese.html 萬國碼轉換表 ( 部份 ) 8
資料的二進位表示法 Sampling the Original Signal Recreating the Signal from the Sampled Values Digitization of an Analog Signal 00000000 00000011 00000111 00000111 00000101 00000000 10000011 10000110 10000110 M 9
資料的二進位表示法 (a) 一個簡單的圖形,(b) 及此圖形的二進位數位化表示法 10
由下而上的硬體設計 電晶體 晶片及電路板間的關係 11
由下而上的硬體設計 x NOT 閘 x Gate 閘極 Drain 汲極 x y AND 閘 x y Source 源極 x y OR 閘 x + y 電晶體作為開關的簡化模型 基本邏輯閘 12
由下而上的硬體設計 x NOT 閘 x NOT 邏輯閘的硬體實現 :(a) (b) 開關動作,(c) CMOS 反相閘 13
由下而上的硬體設計 (a) 二輸入 CMOS NAND 閘,(b) 二輸入 CMOS NOR 閘 14
由下而上的硬體設計 積項之和 (SOP; sum-of-products) 方法 步驟一 建立真值表 步驟二 使用 AND 和 NOT 建立積項 步驟三 將各積項以 OR 閘組合起來 步驟四 建構最終電路 15
由下而上的硬體設計 1 位元比較器之真值表 電路 x 0 y 0 Output 1 x y 0 1 1 1 0 1 0 0 1 x y ( x y) + ( x y) 16
由下而上的硬體設計 1 位元加法器 The 1-ADD Circuit and Truth Table 17
由下而上的硬體設計 N 位元加法器 + s N a b s N 1 N 1 N 1 a b s N 2 N 2 N 2 L L L a b s 1 1 1 a b s 0 0 0 18
電腦硬體架構 馮紐曼 (Von Neumann) 架構之主要子系統 : Memory ( 記憶體 ) Input/Output ( 輸入 / 輸出 ) Arithmetic/Logic unit ( 算術 / 邏輯單元 ) Control unit ( 控制單元 ) 儲存程式概念 指令的循序執行 19
電腦硬體架構 馮紐曼架構之主要子系統 20
電腦硬體架構 RAM (Random Access Memory 隨機存取記憶體 ) Memory made of addressable cells Current standard cell size is 8 bits All memory cells accessed in equal time Memory address Unsigned binary number N long Address space is then 2 N cells 21
電腦硬體架構 記憶體位址暫存器 記憶體位址解碼器 記憶體資料暫存器 隨機存取記憶體的電路架構 22
電腦硬體架構 Fetch operation ( 讀取資料 ) The address of the desired memory cell is moved into the MAR Fetch/store controller signals a fetch, accessing the memory cell The value at the MAR s location flows into the MDR 23
電腦硬體架構 Store operation ( 儲存資料 ) The address of the cell where the value should go is placed in the MAR The new value is placed in the MDR Fetch/store controller signals a store, copying the MDR s value into the desired cell 24
Figure 5.7 Overall RAM Organization 25
電腦硬體架構 輸入 / 輸出單元 : 內存資料與電腦外部的溝通介面 Human interfaces: monitor, keyboard, mouse Archival storage: not dependent on constant power External devices vary tremendously from each other 26
電腦硬體架構 Volatile storage ( 揮發性儲存 ) Information disappears when the power is turned off Example: RAM Nonvolatile storage ( 非揮發性儲存 ) Information does not disappear when the power is turned off Example: mass storage devices such as disks and tapes 27
電腦硬體架構 算術 / 邏輯單元 1. 算術運算 2. 比較 ( 大小 相等 ) 3. 布林邏輯運算 28
電腦硬體架構 控制單元 Task 自記憶體讀取下一個指令 解碼以決定要執行什麼 執行 : 送訊號 資料到 ALU I/O 等 29
機器語言 Can be decoded and executed by control unit Parts of instructions Operation code (op code) Unique unsigned-integer code assigned to each machine language operation Address field(s) Memory addresses of the values on which operation will work 30
機器語言 Figure 5.14 Typical Machine Language Instruction Format 00001001 0000000001100011 0000000001100100 op code address 1 address 2 ADD X, Y 31
Machine Language: 0000 001000001 0011 001000010 0001 001000000 0111 001000000 001000001 1001 000101100 1110 001000001 001000010 1000 000101101 1110 001000000 001000010 32
機器語言 Operations of machine language Data transfer Move values to and from memory and registers Arithmetic/logic Perform ALU operations that produce numeric values 33
機器語言 Operations of machine language (continued) Compares Set bits of compare register to hold result Branches Jump to a new memory address to continue processing 34
組合語言 機器語言與組合語言對應表 機器語言運算碼 0000 0001 0010 0011 0100 0101 0110 M 1111 組合語言指令 LOAD X STORE X CLEAR X ADD X SUB X INCR X JUMP X 略 HALT 意義 CON(X) R R CON(X) 0 CON(X) R + CON(X) R R CON(X) R CON(X) + 1 CON(X) 下個指令由位址 X 取得 --- 停止程式執行 35
組合語言.BEGIN LOAD X STORE Y INCR Y M X:.DATA 3 Y:.DATA 1.END 指令段 資料段 36
高階語言 37
高階語言 FORTRAN VISUAL BASIC Do 6, LOOP = 1, 10 READ *, A, B OUT = (A - B) / 4.0 PRINT *, A, B, OUT 6 CONTINUE END Dim j, out out = 0 For j = 1 To 5 out = out + 2 * j Next j 38
高階語言 C 語言 #include <stdio.h> void main(void) { int x, sum, i; /* 宣告 x, sum, i 為整數變數 */ for (sum = 0, i = 1; i <= 5; i = i + 1) { printf( Enter x: ); /* 在螢幕上顯示字串 */ scanf( %d, &x); /* 由鍵盤讀入數值到 x*/ sum = sum + x;} printf( sum = %d\n, sum); /* 列印 sum*/ } 39
高階語言 JAVA public class ArrayExample{ /** Provide an example of declaring an Array using different methodologies **/ public static void declareexample(){ System.out.println(); System.out.println( +===============+ ); System.out.println( ); System.out.println( Array Declare ); System.out.println( );; System.out.println( +===============+ ); System.out.println(); // Example 1 // First declare a reference, then construct it int[ ] ExampleArray1; ExampleArray1 = new int[24]; M 40
高階語言 高階程式語言的分類 種類 命令式 (Imperative) 物件導向 (Object- Oriented) 函數式 (Functional) 邏輯式 (Logical) ADA BASIC C COBOL FORTRAN PASCAL ASP.NET C++ JAVA LISP PROLOG 程式語言 41
作業系統 (1) 中央處理器的管理 (2) 記憶體的管理 (3) 檔案的管理 (4) 週邊設備的管理 (5) 程序的管理 42
附註 本投影片部分內容取材自 : G. M. Schneider and J. L. Gersting, Invitation to Computer Science, 3rd Edition: C++ Version, Thomson Course Technology, 2004. 趙坤茂, 張雅惠教授, 黃寶萱, 計算機概論, 全華科技圖書公司出版 (2008) 43