軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/cs/3c_tech_life-chap2.pdf · 4...

43
1 Chapter II 軟硬之間—電腦的程式與硬體

Upload: others

Post on 03-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

1

Chapter II軟硬之間—電腦的程式與硬體

Page 2: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

2

資料的二進位表示法

資訊在電腦外部及內部表示法上的不同

Page 3: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

3

資料的二進位表示法

二進位與十進位轉換表

Page 4: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

4

資料的二進位表示法

1035 0000010000001011

-10351000010000001011

1’s補數

1111101111110100

2’s補數

1111101111110101負整數表示法

直接符號

Page 5: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

5

資料的二進位表示法

浮點數表示法

Page 6: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

6

資料的二進位表示法

字元(文字)對應到二進位數編碼

ASCII code (美國國家資訊交換標準碼)set

8 bits per character; 256 character codes

UNICODE code (萬國碼)set

16 bits per character; 65,536 character codes

字串是由字元以某種編碼方式所組成的

Page 7: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

7

Keyboard: CASCII Code: 67Binary: 01000011

ASCII碼轉換表

Page 8: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

8

資料的二進位表示法

http://www.unicode.org/http://www.unicode.org/standard/translations/t-chinese.html

萬國碼轉換表(部份)

Page 9: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

9

資料的二進位表示法

Digitization of an Analog Signal

Sampling the Original Signal

Recreating the Signal from the Sampled Values

000000000000001100000111000001110000010100000000100000111000011010000110

M

Page 10: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

10

資料的二進位表示法

(a) 一個簡單的圖形,(b) 及此圖形的二進位數位化表示法

Page 11: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

11

由下而上的硬體設計

電晶體、晶片及電路板間的關係

Page 12: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

12

由下而上的硬體設計

x x

xy yx ⋅

xy yx +

基本邏輯閘

NOT閘

AND閘

OR閘

電晶體作為開關的簡化模型

Gate閘極

Drain汲極

Source源極

Page 13: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

13

由下而上的硬體設計

x xNOT閘

NOT邏輯閘的硬體實現:(a) 、(b)開關動作,(c) CMOS反相閘

Page 14: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

14

由下而上的硬體設計

(a) 二輸入CMOS NAND閘,(b) 二輸入CMOS NOR閘

Page 15: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

15

由下而上的硬體設計

『積項之和』(SOP; sum-of-products)方法

步驟一、建立真值表

步驟二、使用AND和NOT建立積項

步驟三、將各積項以OR閘組合起來

步驟四、建構最終電路

Page 16: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

16

由下而上的硬體設計

1位元比較器之真值表、電路

111001010100

Outputyx

yx ⋅

yx ⋅

)()( yxyx ⋅+⋅

Page 17: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

17

由下而上的硬體設計

The 1-ADD Circuit and Truth Table

1位元加法器

Page 18: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

18

由下而上的硬體設計

0121

0121

0121

sssssbbbbaaaa

NNN

NN

NN

L

L

L

−−

−−

−−

+N位元加法器

Page 19: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

19

馮紐曼(Von Neumann)架構之主要子系統:

Memory (記憶體)Input/Output (輸入/輸出)Arithmetic/Logic unit (算術/邏輯單元)Control unit (控制單元)

儲存程式概念

指令的循序執行

電腦硬體架構

Page 20: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

20

電腦硬體架構

馮紐曼架構之主要子系統

Page 21: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

21

電腦硬體架構

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 2N cells

Page 22: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

22

電腦硬體架構

隨機存取記憶體的電路架構

記憶體位址暫存器

記憶體位址解碼器 記憶體資料暫存器

Page 23: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

23

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

電腦硬體架構

Page 24: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

24

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

電腦硬體架構

Page 25: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

25

Figure 5.7Overall RAM Organization

Page 26: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

26

電腦硬體架構

輸入/輸出單元:內存資料與電腦外部的溝通介面

Human interfaces: monitor, keyboard, mouse

Archival storage: not dependent on constant power

External devices vary tremendously from each other

Page 27: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

27

電腦硬體架構

Volatile storage (揮發性儲存)Information disappears when the power is turned offExample: RAM

Nonvolatile storage (非揮發性儲存)Information does not disappear when the power is turned offExample: mass storage devices such as disks and tapes

Page 28: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

28

電腦硬體架構

算術/邏輯單元

1.算術運算2.比較(大小、相等)3.布林邏輯運算

Page 29: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

29

電腦硬體架構

控制單元

Task自記憶體讀取下一個指令

解碼以決定要執行什麼

執行:送訊號、資料到ALU、I/O等

Page 30: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

30

機器語言

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

Page 31: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

31

機器語言

Figure 5.14Typical Machine Language Instruction Format

00001001 0000000001100011 0000000001100100op code address 1 address 2→ ADD X, Y

Page 32: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

32

Machine Language:

0000 001000001

0011 001000010

0001 001000000

0111 001000000 001000001

1001 000101100

1110 001000001 001000010

1000 000101101

1110 001000000 001000010

Page 33: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

33

機器語言

Operations of machine language

Data transfer

Move values to and from memory and registers

Arithmetic/logic

Perform ALU operations that produce numeric values

Page 34: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

34

機器語言

Operations of machine language (continued)

Compares

Set bits of compare register to hold result

Branches

Jump to a new memory address to continue processing

Page 35: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

35

組合語言

機器語言與組合語言對應表M

停止程式執行HALT1111---略

下個指令由位址X取得JUMP X0110CON(X) + 1 → CON(X)INCR X0101R – CON(X) → RSUB X0100R + CON(X) → RADD X00110 → CON(X)CLEAR X0010R → CON(X)STORE X0001CON(X) → RLOAD X0000

意義組合語言指令機器語言運算碼

M

Page 36: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

36

組合語言

.BEGINLOAD XSTORE YINCR Y

X: .DATA 3Y: .DATA 1.END

M

指令段

資料段

Page 37: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

37

高階語言

Page 38: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

38

高階語言

• FORTRAN VISUAL BASICDo 6, LOOP = 1, 10

READ * , A , BOUT = (A - B) / 4.0PRINT * , A , B , OUT

6 CONTINUEEND

Dim j, outout = 0For j = 1 To 5

out = out + 2 * jNext j

Page 39: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

39

高階語言

• 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*/}

Page 40: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

40

高階語言

• 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 itint[ ] ExampleArray1;ExampleArray1 = new int[24];

M

Page 41: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

41

高階語言

•高階程式語言的分類

PROLOG邏輯式(Logical)LISP函數式(Functional)

ASP.NET、C++、JAVA物件導向(Object-Oriented)

ADA 、BASIC、C、COBOL、FORTRAN、PASCAL

命令式(Imperative)程式語言種類

Page 42: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

42

作業系統

(1)中央處理器的管理

(2)記憶體的管理

(3)檔案的管理

(4)週邊設備的管理

(5)程序的管理

Page 43: 軟硬之間—電腦的程式與硬體web.nchu.edu.tw/~ycchiang/CS/3C_Tech_Life-Chap2.pdf · 4 資料的二進位表示法 1035 0000010000001011-1035 1000010000001011 1’s補數

43

附註

• 本投影片部分內容取材自:

– G. M. Schneider and J. L. Gersting, Invitation to Computer Science, 3rd Edition: C++ Version, Thomson Course Technology, 2004.

– 趙坤茂, 張雅惠教授, 黃寶萱, 計算機概論, 全華科技圖書公司出版 (2008)。