Download presentation
Presentation is loading. Please wait.
1
Chapter 2 Data Representation
2
OBJECTIVES After reading this chapter, the reader should be able to:
Define data types. Visualize how data are stored inside a computer. Understand the differences between text, numbers, images, video, and audio. Work with hexadecimal and octal notations.
3
2.1 DATA TYPES
4
Different types of data
Figure 2-1 Different types of data
5
Note: The computer industry uses the term “multimedia” to define information that contains numbers, text, images, audio, and video.
6
2.2 DATA INSIDE THE COMPUTER
7
Figure 2-2 Bit pattern
8
Examples of bit patterns
Figure 2-3 Examples of bit patterns
9
2.3 REPRESENTING DATA
10
Representing symbols using bit patterns
Figure 2-4 Representing symbols using bit patterns
11
Table 2.1 Number of symbols and bit pattern length
4 8 16 … 128 256 65,536 Bit Pattern Length 1 2 3 4 … 7 8 16
12
Representation of the word
Figure 2-5 Representation of the word “BYTE” in ASCII code
14
Unicode 16 bits e.g. 趙(8D99) 坤(5764) 茂(8302)
18
Image representation methods
Figure 2-6 Image representation methods
19
Bitmap graphic method of a black-and-white image
Figure 2-7 Bitmap graphic method of a black-and-white image
20
Representation of color pixels
Figure 2-8 Representation of color pixels
21
Figure 2-9 Audio representation
22
2.4 HEXADECIMAL NOTATION
23
Note: A 4-bit pattern can be represented by a hexadecimal digit, and vice versa.
24
Table 2.2 Hexadecimal digits
Bit Pattern 0000 0001 0010 0011 0100 0101 0110 0111 Hex Digit 1 2 3 4 5 6 7 Bit Pattern 1000 1001 1010 1011 1100 1101 1110 1111 Hex Digit 8 9 A B C D E F
25
Binary to hexadecimal and hexadecimal to binary transformation
Figure 2-10 Binary to hexadecimal and hexadecimal to binary transformation
26
Example 1 Show the hexadecimal equivalent of the bit pattern Solution Each group of 4 bits is translated to one hexadecimal digit. The equivalent is xCE2.
27
Show the hexadecimal equivalent of the bit pattern 0011100010.
Example 2 Show the hexadecimal equivalent of the bit pattern Solution Divide the bit pattern into 4-bit groups (from the right). In this case, add two extra 0s at the left to make the number of bits divisible by 4. So you have , which is translated to x0E2.
28
Example 3 What is the bit pattern for x24C? Solution Write each hexadecimal digit as its equivalent bit pattern to get
29
2.5 OCTAL NOTATION
30
A 3-bit pattern can be represented by an octal digit, and vice versa.
Note: A 3-bit pattern can be represented by an octal digit, and vice versa.
31
Table Octal digits Bit Pattern 000 001 010 011 Oct Digit 1 2 3 Bit Pattern 100 101 110 111 Oct Digit 4 5 6 7
32
Binary to octal and octal to binary transformation
Figure 2-11 Binary to octal and octal to binary transformation
33
Example 4 Show the octal equivalent of the bit pattern Solution Each group of 3 bits is translated to one octal digit. The equivalent is 0562, o562, or 5628.
34
Show the octal equivalent of the bit pattern 1100010.
Example 5 Show the octal equivalent of the bit pattern Solution Divide the bit pattern into 3-bit groups (from the right). In this case, add two extra 0s at the left to make the number of bits divisible by 3. So you have , which is translated to 1428.
35
Write each octal digit as its equivalent bit pattern to get 010100.
Example 6 What is the bit pattern for 248? Solution Write each octal digit as its equivalent bit pattern to get
36
一個小小的問題 Oct-這個字根代表8; Dec-這個字根代表10,為什麼October 不是八月而是十月?為什麼 December不是十月而是十二月?
37
因為插入了七月和八月 July源於凱撒(Julius Caesar) 之名,凱撒原是一位有名的羅馬將領,後來當了羅馬皇帝。在這之前就有曆法,那時是以March 為一年的開端,而July是第十五個月;到了凱撒當皇帝便修改曆法,將一年的開始訂為January,而將July 提升到第七位,這個改變一直沿用至今。 凱撒大帝之後,他的兒子奧古斯都(Augustus)繼承王位,人們尊稱他為Augustus,其意義乃代表高貴 (Noble),於是他學凱撒將他的幸運月,以自己的封號命名,並從二月挪一天過來,變成三十一日。 那二月為什麼只有二十八天呢?
38
二月被砍過兩天 二月為什麼通常只有二十八天?
凱撒(Julius Caesar) 修改曆法時,本來規定每年十二個月裡,逢單是大月三十一日,逢雙是小月三十日,但是這樣算下來,一年就變成三百六十六日,所以必須設法在一年中扣去一天。那時候判處死刑的人犯均在二月分執行,因此人們認為二月是不吉利的月分,既然要扣除一天,那麼就由二月分來扣掉,讓不吉利的日子減少一天,因此二月分就成了二十九日。 後來奧古斯都(Augustus)繼凱撒之後當了羅馬皇帝,他發現凱撒是七月生的,而七月是逢單為大月三十一日;他不服氣,為了表示自己也偉大,就把自己八月出生的月分改為大月三十一日。糟了又多出一天怎麼辦?那還是由二月分來扣除,因此結果二月分就變成二十八日。
39
Number Representation
Chapter 3 Number Representation
40
OBJECTIVES After reading this chapter, the reader should be able to :
Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer inside a computer: unsigned, sign-and-magnitude, one’s complement, and two’s complement. Understand the Excess system that is used to store the exponential part of a floating-point number. Understand how floating numbers are stored inside a computer using the exponent and the mantissa.
41
3.1 DECIMAL AND BINARY
42
Figure 3-1 Decimal system
43
Figure 3-2 Binary system
44
3.2 CONVERSION
45
Binary to decimal conversion
Figure 3-3 Binary to decimal conversion
46
Convert the binary number 10011 to decimal.
Example 1 Convert the binary number to decimal. Solution Write out the bits and their weights. Multiply the bit by its corresponding weight and record the result. At the end, add the results to get the decimal number. Binary Weights Decimal
47
Convert the decimal number 35 to binary.
Example 2 Convert the decimal number 35 to binary. Solution Write out the number at the right corner. Divide the number continuously by 2 and write the quotient and the remainder. The quotients move to the left, and the remainder is recorded under each quotient. Stop when the quotient is zero. 0 1 2 4 8 17 Dec. Binary
48
Decimal to binary conversion
Figure 3-4 Decimal to binary conversion
49
Changing fractions to binary
Figure 3-7 Changing fractions to binary
50
Transform the fraction 0.875 to binary
Example 17 Transform the fraction to binary Solution Write the fraction at the left corner. Multiply the number continuously by 2 and extract the integer part as the binary digit. Stop when the number is 0.0. 0.0
51
Transform the fraction 0.4 to a binary of 6 bits.
Example 18 Transform the fraction 0.4 to a binary of 6 bits. Solution Write the fraction at the left cornet. Multiply the number continuously by 2 and extract the integer part as the binary digit. You can never get the exact binary representation. Stop when you have 6 bits. 0.4 1.6
52
3.4 INTEGER REPRESENTATION
53
Figure 3-5 Range of integers
54
Figure 3-6 Taxonomy of integers
55
Table 3.1 Range of unsigned integers
# of Bits 8 16 Range ,535
56
Store 7 in an 8-bit memory location.
Example 3 Store 7 in an 8-bit memory location. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The number is stored in the memory location.
57
Store 258 in a 16-bit memory location.
Example 4 Store 258 in a 16-bit memory location. Solution First change the number to binary Add seven 0s to make a total of N (16) bits, The number is stored in the memory location.
58
Table 3.2 Example of storing unsigned integers in
two different computers (一個為8-bit; 另一個為16-bit) Decimal 7 234 258 24,760 1,245,678 8-bit allocation overflow 16-bit allocation overflow
59
Using the procedure shown in Figure 3.3 , the number in decimal is 43.
Example 5 Interpret in decimal if the number was stored as an unsigned integer. Solution Using the procedure shown in Figure 3.3 , the number in decimal is 43.
60
-------------------------------------------------------
Table Range of sign-and-magnitude integers # of Bits 8 16 32 Range -2,147,483, ,147,483,647
61
Note: In sign-and-magnitude representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive.If it is 1, the number is negative.
62
There are two 0s in sign-and- magnitude
Note: There are two 0s in sign-and- magnitude representation: positive and negative. In an 8-bit allocation: +0
63
Example 6 Store +7 in an 8-bit memory location using sign-and-magnitude representation. Solution First change the number to binary 111. Add four 0s to make a total of N-1 (7) bits, Add an extra zero because the number is positive. The result is:
64
Example 7 Store –258 in a 16-bit memory location using sign-and-magnitude representation. Solution First change the number to binary Add six 0s to make a total of N-1 (15) bits, Add an extra 1 because the number is negative. The result is:
65
------------------------------
Table 3.4 Example of storing sign-and-magnitude integers in two computers Decimal +7 -124 +258 -24,760 8-bit allocation overflow 16-bit allocation
66
Example 8 Interpret in decimal if the number was stored as a sign-and-magnitude integer. Solution Ignoring the leftmost bit, the remaining bits are This number in decimal is 59. The leftmost bit is 1, so the number is –59.
67
There are two 0s in one’s complement
Note: There are two 0s in one’s complement representation: positive and negative. In an 8-bit allocation: +0
68
One’s complement (一位補數法)
If the sign is positive (0), no more action is needed; If the sign is negative, every bit is complemented.
69
-------------------------------------------------------
Table Range of one’s complement integers # of Bits 8 16 32 Range -2,147,483, ,147,483,647
70
Note: In one’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive.If it is 1, the number is negative.
71
Example 9 Store +7 in an 8-bit memory location using one’s complement representation. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The sign is positive, so no more action is needed. The result is:
72
Example 10 Store –258 in a 16-bit memory location using one’s complement representation. Solution First change the number to binary Add seven 0s to make a total of N (16) bits, The sign is negative, so each bit is complemented. The result is:
73
------------------------------
Table 3.6 Example of storing one’s complement integers in two different computers Decimal +7 -7 +124 -124 +24,760 -24,760 8-bit allocation overflow 16-bit allocation
74
Example 11 Interpret in decimal if the number was stored as a one’s complement integer. Solution The leftmost bit is 1, so the number is negative. First complement it . The result is The complement in decimal is 9. So the original number was –9. Note that complement of a complement is the original number.
75
Note: One’s complement means reversing all bits. If you one’s complement a positive number, you get the corresponding negative number. If you one’s complement a negative number, you get the corresponding positive number. If you one’s complement a number twice, you get the original number.
76
Note: Two’s complement is the most common, the most important, and the most widely used representation of integers today.
77
Two’s complement If the sign is positive, no further action is needed;
If the sign is negative, leave all the rightmost 0s and the first 1 unchanged. Complement the rest of the bits e.g 變成負數
78
Two’s complement的另類看法
-) One’s complement +1
79
-------------------------------------------------------
Table 3.7 Range of two’s complement integers # of Bits 8 16 32 Range -128 -32,768 -2,147,483,648 ,767 ,147,483,647
80
Note: In two’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 1, the number is negative.
81
Example 12 Store +7 in an 8-bit memory location using two’s complement representation. Solution First change the number to binary 111. Add five 0s to make a total of N (8) bits, The sign is positive, so no more action is needed. The result is:
82
Example 13 Store –40 in a 16-bit memory location using two’s complement representation. Solution First change the number to binary Add ten 0s to make a total of N (16) bits, The sign is negative, so leave the rightmost 0s up to the first 1 (including the 1) unchanged and complement the rest. The result is:
83
------------------------------
Table 3.8 Example of storing two’s complement integers in two different computers Decimal +7 -7 +124 -124 +24,760 -24,760 8-bit allocation overflow 16-bit allocation
84
There is only one 0 in two’s complement:
Note: There is only one 0 in two’s complement: In an 8-bit allocation: 0
85
Example 14 Interpret in decimal if the number was stored as a two’s complement integer. Solution The leftmost bit is 1. The number is negative. Leave 10 at the right alone and complement the rest. The result is The two’s complement number is 10. So the original number was –10.
86
Note: Two’s complement can be achieved by reversing all bits except the rightmost bits up to the first 1 (inclusive). If you two’s complement a positive number, you get the corresponding negative number. If you two’s complement a negative number, you get the corresponding positive number. If you two’s complement a number twice, you get the original number.
87
Contents of Memory ------------
Table Summary of integer representation Contents of Memory 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Unsigned 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sign-and-Magnitude +0 +1 +2 +3 +4 +5 +6 +7 -0 -1 -2 -3 -4 -5 -6 -7 One’s Complement +0 +1 +2 +3 +4 +5 +6 +7 -7 -6 -5 -4 -3 -2 -1 -0 Two’s Complement +0 +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1
88
3.5 EXCESS SYSTEM
89
Represent –25 in Excess_127 using an 8-bit allocation.
Example 15 Represent –25 in Excess_127 using an 8-bit allocation. Solution First add 127 to get 102. This number in binary is Add one bit to make it 8 bits in length. The representation is
90
Example 16 Interpret if the representation is Excess_127. Solution First change the number to decimal. It is 254. Then subtract 127 from the number. The result is decimal 127.
91
3.5 FLOATING-POINT REPRESENTATION
92
Table 3.10 Example of normalization
Original Number Original Number Move 6 2 6 3 Normalized x x x -2-3 x
93
IEEE standards for floating-point representation
Figure 3-8 IEEE standards for floating-point representation
94
Show the representation of the normalized number + 26 x 1.01000111001
Example 19 Show the representation of the normalized number x Solution The sign is positive. The Excess_127 representation of the exponent is 133. You add extra 0s on the right to make it 23 bits. The number in memory is stored as:
95
Mantissa -------------------------------
Table Example of floating-point representation Number -22 x +2-6 x x Sign ---- 1 Exponent Mantissa
96
Interpret the following 32-bit floating-point number
Example 20 Interpret the following 32-bit floating-point number Solution The sign is negative. The exponent is –3 (124 – 127). The number after normalization is x
97
3.6 HEXADECIMAL NOTATION
98
Chapter 4 Operations on Bits
99
OBJECTIVES After reading this chapter, the reader should be able to:
Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits. Understand the applications of logical operations using masks. Understand the shift operations on numbers and how a number can be multiplied or divided by powers of two using shift operations.
100
Figure 4-1 Operations on bits
101
4.1 ARITHMETIC OPERATIONS
102
Number of 1s ------------
Table 4.1 Adding bits Number of 1s None One Two Three Result 1 Carry 1
103
Rule of Adding Integers in Two’s Complement
Note: Rule of Adding Integers in Two’s Complement Add 2 bits and propagate the carry to the next column. If there is a final carry after the leftmost column addition, discard it.
104
簡要解釋為何two’s complement可以這樣做運算
假設是n bits 正數 + 正數 (和一般情況一樣) 負數(-x) + 負數(-y) -x在two’s complement表示值為 2n-x -y在two’s complement表示值為 2n-y 2n - x + 2n - y = 2n + (2n - (x+y)) Carry (進位) -(x+y)的two’s complement表示法
105
簡要解釋為何two’s complement可以這樣做運算 (續前頁)
正數 (x) + 負數 (-y) -y在two’s complement表示值為 2n-y 得 2n+x-y (1) x >= y x-y為正值; 2n為進位 (2) x <y 2n+x-y = 2n-(y-x)
106
Example 1 Add two numbers in two’s complement representation: (+17) + (+22) (+39) Solution Carry Result 39
107
Example 2 Add two numbers in two’s complement representation: (+24) + (-17) (+7) Solution Carry Result +7
108
Example 3 Add two numbers in two’s complement representation: (-35) + (+20) (-15) Solution Carry Result -15
109
Example 4 Add two numbers in two’s complement representation: (+127) + (+3) (+130) Solution Carry Result -126 (Error) An overflow has occurred.
110
Range of numbers in two’s complement representation
Note: Range of numbers in two’s complement representation - (2N-1) (2N-1 –1)
111
Two’s complement numbers visualization
Figure 4-2 Two’s complement numbers visualization
112
Note: When you do arithmetic operations on numbers in a computer, remember that each number and the result should be in the range defined by the bit allocation.
113
Example 5 Subtract 62 from 101 in two’s complement: (+101) - (+62) (+101) + (-62) Solution Carry Result 39 The leftmost carry is discarded.
114
Example 6 Add two floats: Solution The exponents are 5 and 3. The numbers are: +25 x and x Make the exponents the same. (+25 x )+ (+25 x ) +25 x After normalization +26 x , which is stored as:
115
4.2 LOGICAL OPERATIONS
116
Unary and binary operations
Figure 4-3 Unary and binary operations
117
Figure 4-4 Logical operations
118
Figure 4-5 Truth tables
119
Figure 4-6 NOT operator
120
Example 7 Use the NOT operator on the bit pattern Solution Target NOT Result
121
Figure 4-7 AND operator
122
Example 8 Use the AND operator on bit patterns and Solution Target AND Result
123
Inherent rule of the AND operator
Figure 4-8 Inherent rule of the AND operator
124
Figure 4-9 OR operator
125
Example 9 Use the OR operator on bit patterns and Solution Target OR Result
126
Inherent rule of the OR operator
Figure 4-10 Inherent rule of the OR operator
127
Figure 4-11 XOR operator
128
Example 10 Use the XOR operator on bit patterns and Solution Target XOR Result
129
Inherent rule of the XOR operator
Figure 4-12 Inherent rule of the XOR operator
130
More about XOR 一連串的bits做 XOR, 若奇數個1, 則結果為1;若偶數個1則結果為0 1 XOR
131
Figure 4-13 Mask
132
Example of unsetting specific bits
Figure 4-14 Example of unsetting specific bits
133
Example 11 Use a mask to unset (clear) the 5 leftmost bits of a pattern. Test the mask with the pattern Solution The mask is Target AND Mask Result
134
Solution on the next slide.
Example 12 Imagine a power plant that pumps water to a city using eight pumps. The state of the pumps (on or off) can be represented by an 8-bit pattern. For example, the pattern shows that pumps 1 to 3 (from the right), 7 and 8 are on while pumps 4, 5, and 6 are off. Now assume pump 7 shuts down. How can a mask show this situation? Solution on the next slide.
135
Solution Use the mask to AND with the target pattern. The only 0 bit (bit 7) in the mask turns off the seventh bit in the target. Target AND Mask Result
136
Example of setting specific bits
Figure 4-15 Example of setting specific bits
137
Example 13 Use a mask to set the 5 leftmost bits of a pattern. Test the mask with the pattern Solution The mask is Target OR Mask Result
138
Example 14 Using the power plant example, how can you use a mask to to show that pump 6 is now turned on? Solution Use the mask Target OR Mask Result
139
Example of flipping specific bits
Figure 4-16 Example of flipping specific bits
140
Example 15 Use a mask to flip the 5 leftmost bits of a pattern. Test the mask with the pattern Solution Target XOR Mask Result
141
4.3 SHIFT OPERATIONS
142
Figure 4-17 Shift operations
143
Example 16 Show how you can divide or multiply a number by 2 using shift operations. Solution If a bit pattern represents an unsigned number, a right-shift operation divides the number by two. The pattern represents 59. When you shift the number to the right, you get , which is 29. If you shift the original number to the left, you get , which is 118.
144
Example 17 Use a combination of logical and shift operations to find the value (0 or 1) of the fourth bit (from the right). Solution Use the mask to AND with the target to keep the fourth bit and clear the rest of the bits. Continued on the next slide
145
Solution (continued) Target a b c d e f g h AND Mask Result e Shift the new pattern three times to the right e000 00000e00 e0 e Now it is easy to test the value of the new pattern as an unsigned integer. If the value is 1, the original bit was 1; otherwise the original bit was 0.
146
Computer Organization (計算機組織)
Chapter 5 Computer Organization (計算機組織)
147
OBJECTIVES After reading this chapter, the reader should be able to:
Distinguish between the three components of a computer hardware. List the functionality of each component. Understand memory addressing and calculate the number of bytes for a specified purpose. Distinguish between different types of memories. Understand how each input/output device works. Continued on the next slide
148
OBJECTIVES (continued)
Understand the systems used to connect different components together. Understand the addressing system for input/output devices. Understand the program execution and machine cycles. Distinguish between programmed I/O, interrupt-driven I/O and direct memory access (DMA). Understand the two major architectures used to define the instruction sets of a computer: CISC and RISC.
149
Computer hardware (subsystems)
Figure 5-1 Computer hardware (subsystems)
150
5.1 CENTRAL PROCESSING UNIT (CPU)
151
Figure 5-2 CPU
152
5.2 MAIN MEMORY
153
Table 5.1 Memory units kilobyte megabyte gigabyte terabyte petabyte
exabyte Exact Number of bytes 210 bytes 220 bytes 230 bytes 240 bytes 250 bytes 260 bytes Approximation 103 bytes 106 bytes 109 bytes 1012 bytes 1015 bytes 1018 bytes
154
Figure 5-3 Main memory
155
Memory addresses are defined using unsigned binary integers.
Note: Memory addresses are defined using unsigned binary integers.
156
Example 1 A computer has 32 MB (megabytes) of memory. How many bits are needed to address any single byte in memory? Solution The memory address space is 32 MB, or 225 (25 x 220). This means you need log2 225 or 25 bits, to address each byte.
157
Example 2 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? Solution The memory address space is 128 MB, which means 227. However, each word is 8 (23) bytes, which means that you have 224 words. This means you need log2 224 or 24 bits, to address each word.
158
Memory Types RAM (Random access memory): ROM (Read only memory)
SRAM (Static RAM) (flip-flop gates) DRAM (Dynamic RAM) ROM (Read only memory) PROM (programmable) EPROM (erasable programmable) EEPROM (electronically erasable programmable)
159
A simple flip-flop circuit
Set Reset
160
Setting the output of a flip-flop to 1
161
Setting the output of a flip-flop to 1 (continued)
162
Setting the output of a flip-flop to 1
163
Another way of constructing a flip-flop
164
Figure 5-4 Memory hierarchy
165
Figure 5-5 Cache
166
5.3 INPUT / OUTPUT
167
Physical layout of a magnetic disk
Figure 5-6 Physical layout of a magnetic disk
168
Surface organization of a disk
Figure 5-7 Surface organization of a disk
169
Mechanical configuration of a tape
Figure 5-8 Mechanical configuration of a tape
170
Surface organization of a tape
Figure 5-9 Surface organization of a tape
171
Creation and use of CD-ROM
Figure 5-10 Creation and use of CD-ROM
172
3,688,400 bytes per second 4,915,200 bytes per second
Table 5.2 CD-ROM speeds Speed 1x 2x 4x 6x 8x 12x 16x 24x 32x 40x Data Rate 153, bytes per second 307, bytes per second 614, bytes per second 921, bytes per second 1,228, bytes per second 1,843, bytes per second 2,457,600 bytes per second 3,688, bytes per second 4,915,200 bytes per second 6,144,000 bytes per second Approximation 150 KB/s 300 KB/s 600 KB/s 900 KB/s 1.2 MB/s 1.8 MB/s 2.4 MB/s 3.6 MB/s 4.8 MB/s 6 MB/s
173
Figure 5-11 CD-ROM format
174
Figure 5-12 Making a CD-R
175
Figure 5-13 Making a CD-RW
176
single-sided, single-layer single-sided, dual-layer
Table DVD capacities Feature single-sided, single-layer single-sided, dual-layer double-sided, single-layer double-sided, dual-layer Capacity 4.7 GB 8.5 GB 9.4 GB 17 GB
177
5.4 SUBSYSTEM INTERCONNECTION
178
Connecting CPU and memory using three buses
Figure 5-14 Connecting CPU and memory using three buses
179
Connecting I/O devices to the buses
Figure 5-15 Connecting I/O devices to the buses
180
(Small Computer System Interface)
Figure 5-16 SCSI controller (Small Computer System Interface) Daisy Chain
181
FireWire controller (IEEE 1394)
Figure 5-17 FireWire controller (IEEE 1394)
182
(Universal Serial Bus)
Figure 5-18 USB controller (Universal Serial Bus)
183
Isolated I/O addressing
Figure 5-19 Isolated I/O addressing
184
Memory-mapped I/O addressing
Figure 5-20 Memory-mapped I/O addressing
185
5.5 PROGRAM EXECUTION
186
Figure 5-21 Steps of a cycle
187
Contents of memory and register before execution
Figure 5-22 Contents of memory and register before execution
188
registers after each cycle
Figure 5-23.a Contents of memory and registers after each cycle
189
registers after each cycle
Figure 5-23.b Contents of memory and registers after each cycle
190
registers after each cycle
Figure 5-23.c Contents of memory and registers after each cycle
191
Contents of memory and registers after each cycle
Figure 5-23.d Contents of memory and registers after each cycle
192
Figure 5-24 Programmed I/O
193
Figure 5-25 Interrupt-driven I/O
194
DMA connection to the general bus
Figure 5-26 DMA connection to the general bus
195
Figure 5-27 DMA input/output
196
5.6 TWO DIFFERENT ARCHITECTURES
197
Two different architectures
CISC (Complex Instruction Set Computer) Intel RISC (Reduced Instruction Set Computer) PowerPC
198
Chapter 6 Computer Networks
199
OBJECTIVES After reading this chapter, the reader should be able to:
Understand the rationale for the existence of networks. Distinguish between the three types of networks: LANs, MANs, and WANs. Understand the OSI model and TCP/IP. List different connecting devices and the OSI layers in which each device operates. Understand client-server models.
200
6.1 NETWORKS, LARGE AND SMALL (LAN, MAN, WAN)
201
6.2 OSI MODEL
202
Note: The Open Systems Interconnection model is a theoretical model that shows how any two different systems can communicate with each other.
203
Figure 6-1 The OSI model
204
Flow of data in the OSI model
Figure 6-2 Flow of data in the OSI model User network Coding methods Synchronization points Entire message Packet (logical address) Frames (node node) Bit stream signal
205
6.3 CATEGORIES OF NETWORKS
206
Categories of networks
Figure 6-3 Categories of networks
207
Figure 6-4 LANs
208
Figure 6-5 MAN
209
Figure 6-6 WAN
210
6.4 CONNECTING DEVICES
211
Figure 6-7 Connecting devices
212
Figure 6-8 Repeater
213
Repeaters operate at the first layer of the OSI model.
Note: Repeaters operate at the first layer of the OSI model.
214
Figure 6-9 Bridge
215
Bridges operate at the first two layers of the OSI model.
Note: Bridges operate at the first two layers of the OSI model.
216
Figure 6-10 Switch
217
Routers operate at the first three layers of the OSI model.
Note: Routers operate at the first three layers of the OSI model.
218
Figure 6-11 Routers in an internet
219
Connecting devices and the OSI model
Figure 6-12 Connecting devices and the OSI model Router 和 Gateway 現在不太區別了
220
6.5 THE INTERNET AND TCP/IP
221
Figure 6-13 TCP/IP and OSI model
222
IP addresses in dotted-decimal notation
Figure 6-14 IP addresses in dotted-decimal notation
223
Figure 6-15 Client-server model
224
Figure 6-16 FTP
225
Figure 6-17 SMTP
226
Figure 6-18 address
227
Figure 6-19 TELNET
228
Figure 6-20 URL
229
Figure 6-21 Browser
230
Categories of Web documents
Figure 6-22 Categories of Web documents
231
Chapter 7 Operating Systems 作業系統 (電腦的管家婆)
232
OBJECTIVES After reading this chapter, the reader should be able to:
Define the purpose and functions of an operating system. Understand the components of an operating system. Understand the concept of virtual memory. Understand the concept of deadlock and starvation. List some of the characteristics of popular operating systems such as Windows 2000, UNIX, and Linux.
233
Figure 7-1 Computer System
234
7.1 DEFINITION
235
Note: An operating system is an interface between the hardware of a computer and the user (program or human) that facilitates the execution of the other programs and the access to hardware and software resources.
236
7.2 EVOLUTION: Batch systems Time-sharing systems Personal systems
Parallel systems Distributed systems 7.2
237
7.3 COMPONENTS
238
Components of an operating system
Figure 7-2 Components of an operating system
239
Figure 7-3 Monoprogramming
240
Figure 7-4 Multiprogramming
241
Categories of multiprogramming
Figure 7-5 Categories of multiprogramming
242
Figure 7-6 Partitioning
243
Figure 7-7 Paging
244
Figure 7-8 Virtual memory
245
State diagram with the boundaries between a program, a job, and a process
Figure 7-9
246
Figure 7-10 Job scheduler
247
Figure 7-11 Process scheduler
248
Queues for process management
Figure 7-12 Queues for process management
249
Figure 7-13 Deadlock
250
Figure 7-14 Deadlock on a bridge
251
Note: Deadlock occurs when the operating system does not put resource restrictions on processes.
252
Figure 7-15.a Starvation
253
Figure 7-15.b Starvation
254
Figure 7-15.c Starvation
255
Figure 7-16 Dining philosophers
256
POPULAR OPERATING SYSTEMS:
7.4 POPULAR OPERATING SYSTEMS: Unix; Linux; Windows
257
Chapter 8 Algorithms
258
OBJECTIVES After reading this chapter, the reader should be able to:
Understand the concept of an algorithm. Define and use the three constructs for developing algorithms: sequence, decision, and repetition. Understand and use three tools to represent algorithms: flowchart, pseudocode, and structure chart. Understand the concept of modularity and subalgorithms. List and comprehend common algorithms.
259
8.1 CONCEPT
260
Informal definition of an algorithm
Figure 8-1 Informal definition of an algorithm used in a computer
261
Finding the largest integer
Figure 8-2 Finding the largest integer among five integers
262
Defining actions in FindLargest algorithm
Figure 8-3 Defining actions in FindLargest algorithm
263
Figure 8-4 FindLargest refined
264
Generalization of FindLargest
Figure 8-5 Generalization of FindLargest
265
8.2 THREE CONSTRUCTS
266
Figure 8-6 Three constructs
267
8.3 ALGORITHM REPRESENTATION
268
Flowcharts for three constructs
Figure 8-7 Flowcharts for three constructs
269
Pseudocode for three constructs
Figure 8-8 Pseudocode for three constructs
270
Write an algorithm in pseudocode that finds the average of two numbers
Example 1 Write an algorithm in pseudocode that finds the average of two numbers Solution See Algorithm 8.1 on the next slide.
271
Algorithm 8.1: Average of two AverageOfTwo Input: Two numbers
Add the two numbers Divide the result by 2 Return the result by step 2 End
272
Write an algorithm to change a numeric grade to a pass/no pass grade.
Example 2 Write an algorithm to change a numeric grade to a pass/no pass grade. Solution See Algorithm 8.2 on the next slide.
273
Algorithm 8.2: Pass/no pass Grade Pass/NoPassGrade Input: One number
if (the number is greater than or equal to 70) then 1.1 Set the grade to “pass” else 1.2 Set the grade to “nopass” End if Return the grade End
274
Write an algorithm to change a numeric grade to a letter grade.
Example 3 Write an algorithm to change a numeric grade to a letter grade. Solution See Algorithm 8.3 on the next slide.
275
Algorithm 8.3: Letter grade LetterGrade Input: One number
1. if (the number is between 90 and 100, inclusive) then 1.1 Set the grade to “A” End if 2. if (the number is between 80 and 89, inclusive) then 2.1 Set the grade to “B” Continues on the next slide
276
Letter grade (continued)
Algorithm 8.3: Letter grade (continued) 3. if (the number is between 70 and 79, inclusive) then 3.1 Set the grade to “C” End if 4. if (the number is between 60 and 69, inclusive) then 4.1 Set the grade to “D” Continues on the next slide
277
Letter grade (continued)
Algorithm 8.3: Letter grade (continued) 5. If (the number is less than 60) then 5.1 Set the grade to “F” End if 6. Return the grade End
278
See Algorithm 8.4 on the next slide.
Example 4 Write an algorithm to find the largest of a set of numbers. You do not know the number of numbers. Solution See Algorithm 8.4 on the next slide.
279
Algorithm 8.4: Find largest FindLargest
Input: A list of positive integers Set Largest to 0 while (more integers) if (the integer is greater than Largest) then Set largest to the value of the integer End if End while Return Largest End
280
Write an algorithm to find the largest of 1000 numbers.
Example 5 Write an algorithm to find the largest of 1000 numbers. Solution See Algorithm 8.5 on the next slide.
281
Algorithm 8.5: Find largest of 1000 numbers FindLargest
Input: 1000 positive integers Set Largest to 0 Set Counter to 0 while (Counter less than 1000) if (the integer is greater than Largest) then Set Largest to the value of the integer End if Increment Counter End while Return Largest End
282
8.4 MORE FORMA DEFINITION Ordered set Unambiguous steps Effectiveness
Termination
283
8.5 SUBALGORITHMS
284
Concept of a subalgorithm
Figure 8-9 Concept of a subalgorithm
285
Algorithm 8.6: Find largest FindLargest
Input: A list of positive integers Set Largest to 0 while (more integers) FindLarger End while Return Largest End
286
Subalgorithm: Find larger FindLarger
Input: Largest and current integer if (the integer is greater than Largest) then Set Largest to the value of the integer End if End
287
8.6 BASIC ALGORITHMS
288
Figure 8-10 Summation
289
Figure 8-11 Product
290
Figure 8-12 Selection sort
291
Example of selection sort
Figure 8-13: part I Example of selection sort
292
Example of selection sort
Figure 8-13: part II Example of selection sort
293
Figure 8-14 Selection sort algorithm
294
Figure 8-15 Bubble sort
295
Figure 8-16: part I Example of bubble sort
296
Figure 8-16: part II Example of bubble sort
297
Figure 8-17 Insertion sort
298
Example of insertion sort
Figure 8-18: part I Example of insertion sort
299
Example of insertion sort
Figure 8-18: part II Example of insertion sort
300
Figure 8-19 Search concept
301
Example of a sequential sort
Figure 8-20: Part I Example of a sequential sort
302
Example of a sequential sort
Figure 8-20: Part II Example of a sequential sort
303
Example of a binary sort
Figure 8-21
304
8.1 RECURSION
305
Iterative definition of factorial
Figure 8-22 Iterative definition of factorial
306
Recursive definition of factorial
Figure 8-23 Recursive definition of factorial
307
Tracing recursive solution to factorial problem
Figure 8-24 Tracing recursive solution to factorial problem
308
Algorithm 8.7: Iterative factorial Factorial
Input: A positive integer num Set FactN to 1 Set i to 1 while (i is less than or equal to num) Set FactN to FactN x I Increment i End while Return FactN End
309
Algorithm 8.8: Recursive factorial Factorial
Input: A positive integer num if (num is equal to 0) then return 1 else 1.2 return num x Factorial (num – 1) End if End
310
Programming Languages
Chapter 9 Programming Languages
311
OBJECTIVES After reading this chapter, the reader should be able to:
Have a vision of computer language evolution. Distinguish between machine, assembly, and high-level languages. Understand the process of creating and running a program. Distinguish between the different categories of languages: procedural, object-oriented, functional, declarative, and special. Become familiar with elements of the procedural language C.
312
9.1 EVOLUTION
313
Evolution of computer languages
Figure 9-1 Evolution of computer languages
314
Program 9.1 Program in machine language 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16
315
Note: The only language understood by a computer is machine language.
316
Program 9.2 Program in symbolic language 1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16 Entry main, ^m<r2> subl2 #12,sp jsb C$MAIN_ARGS movab $CHAR_STRING_CON pushal -8(fp) pushal (r2) calls #2,read pushal -12(fp) pushal 3(r2) calls #2,read mull (fp),-12(fp),- pushal 6(r2) calls #2,print clrl r0 ret
317
Program 9.3 Program in C++ language 1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 /* This program reads two integer numbers from the keyboard and prints their product. */ #include <iostream.h> int main (void) { // Local Declarations int number1; int number2; int result; // Statements cin >> number1; cin >> number2; result = number1 * number2; cout << result; return 0; } // main
318
9.2 BUILDING A PROGRAM
319
Figure 9-2 Building a program
320
9.3 PROGRAM EXECUTION
321
Figure 9-3 Program execution
322
9.4 CATEGORIES OF LANGUAGES
323
Categories of languages
Figure 9-4 Categories of languages
324
Function in a functional language
Figure 9-5 Function in a functional language
325
Extracting the third element of a list
Figure 9-6 Extracting the third element of a list
326
Table 9.1 Common tags Beginning Tag ---------------- <HTML>
<HEAD> <BODY> <TITLE> <Hi> <B> <I> <U> <SUB> <SUP> <CENTER> <BR> <OL> <UL> <LI> <IMG> <A> Ending Tag </HTML> </HEAD> </BODY> </TITLE> </Hi> </B> </I> </U> </SUB> </SUP> </CENTER> </OL> </UL> </LI> </A> Meaning document document head document body document title different header levels boldface Italic underlined subscript superscript centered line break ordered list unordered list an item in the list an image an address (hyperlink)
327
Program 9.4 HTML Program <HTML> <HEAD>
<TITLE> Sample Document </TITLE> </HEAD> <BODY> This is the picture of a book: <IMG SRC="Pictures/book1.gif" ALIGN=MIDDLE> </BODY> </HTML>
328
9.5 A PROCEDURAL LANGUAGE: C
329
Figure 9-7 Variables
330
Table 9.2 Arithmetic operators
+ - * / % ++ -- Definition Addition Subtraction Multiplication Division (quotient) Division (remainder) Increment Decrement Example Num * 5 Sum / Count Count % 4 Count ++ Count --
331
Table 9.3 Relational operators
< <= > >= == != Definition Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Example Num1 < 5 Num1 <= 5 Num2 > 3 Num2 >= 3 Num1 == Num2 Num1 != Num2
332
Table 9.4 Logical operators
! && || Definition NOT AND OR Example ! ( Num1 < Num2 ) (Num1 < 5 ) && (Num2 > 10 ) (Num1 < 5 ) || (Num2 > 10 )
333
Table 9.5 Assignment operators
== += -= *= /= %= Example Num = 5 Num += 5 Num -= 5 Num *= 5 Num /= 5 Num %= 5 Meaning Store 5 in Num Num = Num Num = Num Num = Num * 5 Num = Num / 5 Num = Num % 5
334
Figure 9-8 Statements
335
Side effect of a function
Figure 9-9 Side effect of a function
336
Figure 9-10 Function declaration
337
Figure 9-11 if-else statement
338
Figure 9-12 switch statement
339
Figure 9-13 while loop
340
Figure 9-14 for loop
341
do-while loop Figure 9-15
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.