Bài giảng Kiến trúc máy tính (Computer Architecture): Chương 2 - Nguyễn Kim Khánh

47 15 0
Bài giảng Kiến trúc máy tính (Computer Architecture): Chương 2 - Nguyễn Kim Khánh

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chương 2 - Cơ bản về logic số. Những nội dung chính được trình bày trong chương này gồm có: Các hệ đếm cơ bản, đại số boole, các cổng logic, mạch tổ hợp, mạch dãy. Mời các bạn cùng tham khảo để biết thêm các nội dung chi tiết.

NKK-HUST c om Kiến trúc máy tính cu u du o ng th an co ng Chương CƠ BẢN VỀ LOGIC SỐ Nguyễn Kim Khánh Trường Đại học Bách khoa Hà Nội 2017 Kiến trúc máy tính CuuDuongThanCong.com 42 https://fb.com/tailieudientucntt NKK-HUST Nội dung học phần cu u du o ng th an co ng c om Chương Giới thiệu chung Chương Cơ logic số Chương Hệ thống máy tính Chương Số học máy tính Chương Kiến trúc tập lệnh Chương Bộ xử lý Chương Bộ nhớ máy tính Chương Hệ thống vào-ra Chương Các kiến trúc song song 2017 Kiến trúc máy tính CuuDuongThanCong.com 43 https://fb.com/tailieudientucntt NKK-HUST c om Nội dung chương cu u du o ng th an co ng 2.1 Các hệ đếm 2.2 Đại số Boole 2.3 Các cổng logic 2.4 Mạch tổ hợp 2.5 Mạch dãy 2017 Kiến trúc máy tính CuuDuongThanCong.com 44 https://fb.com/tailieudientucntt NKK-HUST Hệ thập phân (Decimal System) người sử dụng Hệ nhị phân (Binary System) máy tính sử dụng Hệ mười sáu (Hexadecimal System) dùng để viết gọn cho số nhị phân du o cu u n ng th an n co ng n c om 2.1 Các hệ đếm 2017 Kiến trúc máy tính CuuDuongThanCong.com 45 https://fb.com/tailieudientucntt NKK-HUST c om Hệ thập phân Cơ số 10 n 10 chữ số: 0,1,2,3,4,5,6,7,8,9 co Dùng n chữ số thập phân biểu diễn 10n giá trị khác nhau: th an n ng n 00 000 = n 99 999 = 10n - cu u du o ng n 2017 Kiến trúc máy tính CuuDuongThanCong.com 46 https://fb.com/tailieudientucntt NKK-HUST Dạng tổng quát số thập phân c om A = an an-1 a1a0 , a-1 a-m an co ng Giá trị A hiểu sau: cu u du o ng th A = an10 n + an−110 n−1 + + a1101 + a010 + a−110 −1 + + a−m10 −m 2017 A= n ∑ a 10 i i i=−m Kiến trúc máy tính CuuDuongThanCong.com 47 https://fb.com/tailieudientucntt NKK-HUST Ví dụ số thập phân n 47 : 10 = dư n : 10 = dư co 472 : 10 = 47 dư an n ng Các chữ số phần nguyên: th u Các chữ số phần lẻ: n 0.38 x 10 = 3.8 phần nguyên = n 0.8 x 10 = 8.0 phần nguyên = cu n du o ng n c om 472.38 = 4x102 + 7x101 + 2x100 + 3x10-1 + 8x10-2 2017 Kiến trúc máy tính CuuDuongThanCong.com 48 https://fb.com/tailieudientucntt NKK-HUST Hệ nhị phân n c om ng co an n th n n = = 2n - u n 00 000 11 111 ng n Cơ số 2 chữ số nhị phân: Chữ số nhị phân gọi bit (binary digit) bit đơn vị thơng tin nhỏ Dùng n bit biểu diễn 2n giá trị khác nhau: du o n Các lệnh chương trình liệu máy tính mã hóa số nhị phân cu n 2017 Kiến trúc máy tính CuuDuongThanCong.com 49 https://fb.com/tailieudientucntt NKK-HUST Số nhị phân 2-bit 3-bit 4-bit 00 000 0000 01 001 0001 010 0010 011 0011 100 0100 101 0101 110 0110 111 0111 1000 1001 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 Biểu diễn số nhị phân c om 1-bit Số thập phân 10 cu u du o ng th an co ng 11 2017 Kiến trúc máy tính CuuDuongThanCong.com https://fb.com/tailieudientucntt 50 NKK-HUST Đơn vị liệu thông tin máy tính c om n n n n th = 210 bytes = 210 KB = 210 MB = 210 GB = 210 TB = 210 PB ng du o n KB (Kilobyte) MB (Megabyte) GB (Gigabyte) TB (Terabyte) PB (Petabyte) EB (Exabyte) u n cu n an co n bit – chữ số nhị phân (binary digit): đơn vị thông tin nhỏ nhất, cho phép nhận hai giá trị: byte tổ hợp bit: biểu diễn 256 giá trị (28) Qui ước đơn vị liệu: ng n 2017 = 1024 bytes = 220bytes (~106) = 230bytes (~109) = 240bytes (~1012) = 250bytes = 260bytes Kiến trúc máy tính CuuDuongThanCong.com 51 https://fb.com/tailieudientucntt NKK-HUST ng cu u du o ng n co n an n 2n đầu vào liệu n đầu vào chọn đầu liệu Mỗi tổ hợp đầu vào chọn (S) xác định đầu vào liệu (D) nối với đầu (F) th n c om Bộ chọn kênh (Multiplexer - MUX) 2017 Kiến trúc máy tính CuuDuongThanCong.com 74 https://fb.com/tailieudientucntt line, which is either or Thus, three of the inputs to the OR gate are always 0, and the output of the OR gate will equal the value of the selected input gate Using ultiplexer connects multiple inputs to a single output.this At regular any time, one of theit is easy to construct multiplexers of size 8-to-1, 16-to-1, NKK-HUST organization, so on representation s selected to be passed to the output A general blockand diagram Multiplexers areinput used in digital circuits to control signal and data routing An n in Figure 11.12 This represents a 4-to-1 multiplexer There are four theprovide loading of the program counter (PC) The value to be loaded into the abeled D0, D1, D2, and D3 One of these lines is example selectedisto the program counter may come from one of several different sources: plexers Bộ chọn kênh đầu vào D0 4-to-1 MUX D2 F ng D1 S1 c om S2 D0 an co D3 S1 du o Figure 11.12 4-to-1 Multiplexer Representation Đầu vào chọn Đầu ra ng S2 th D1 S1 F 0 1 1 D0 D1 D2 D3 cu u S2 2017 F D2 D3 Figure 11.13 Multiplexer Implementation F = D0 • S2 • S1+ D1• S2 • S1+ D2 • S2 • S1+ D3• S2 • S1 Kiến trúc máy tính CuuDuongThanCong.com 75 https://fb.com/tailieudientucntt NKK-HUST Bộ giải mã (Decoder) n c om ng n N đầu vào, 2N đầu Với tổ hợp N đầu vào, có đầu tích cực (khác với đầu cịn lại) Ví dụ: Bộ giải mã co n A0 1 cu A1 0 1 Y3 0 th A0 ng Y3 Y2 Y1 Y0 Y3 Y2 u A1 A0 A1 du o 11 10 01 00 an 2:4 Decoder Y2 0 2017 Y1 0 Y0 0 Y1 Y0 Kiến trúc máy tính CuuDuongThanCong.com 76 https://fb.com/tailieudientucntt NKK-HUST Thực giải mã 11.3 / COMBINATIONAL CIRCUITS A 383 c om 000 D B cu u du o ng th an co ng C 001 D 010 D 011 D 100 D 101 D 110 D 111 D 2017 Figure 11.15 Decoder with Inputs and 23 = Outputs Kiến trúc máy tính CuuDuongThanCong.com 77 https://fb.com/tailieudientucntt NKK-HUST Bộ cộng co Bộ cộng toàn phần 1-bit (Full-adder) cu u du o n Cộng bit Cho phép xây dựng cộng N-bit an n th n Cộng hai bit tạo bit tổng bit nhớ ng n c om Bộ cộng bán phần 1-bit (Half-adder) ng n 2017 Kiến trúc máy tính CuuDuongThanCong.com 78 https://fb.com/tailieudientucntt NKK-HUST Bộ cộng bán phần 1-bit 1 + 0 + 1 + 0 + 1 1 10 ng 1-bit Half Adder an S Đầu Cout S = AÅ B u A B 0 du o S 0 C out = AB cu ng th Đầu vào Cout B co c om A 1 1 1 2017 Kiến trúc máy tính CuuDuongThanCong.com 79 https://fb.com/tailieudientucntt NKK-HUST Bộ cộng tồn phần 1-bit B 1-bit Full Adder S = ABC + ABC + ABC + ABC Cin ng Cout = AB + AC + BC Cout ng S 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 du o u B cu A Đầu th Đầu vào an S Cin 11.3 / COMBINATIONAL CIRCUITS 387 co Cout c om A 2017 0 A B C A B C A B C S Sum A B C A B A C C Carry out B C Kiến trúc máy tính Figure 11.20 Implementation of an Adder CuuDuongThanCong.com https://fb.com/tailieudientucntt 80 Sum = A BC + ABC + ABC + ABC NKK-HUST Thus we have the necessary logic+toBC implement a multiple-bit adder such as Carry = AB + AC shown in Figure 11.21 Note that because the output from each adder depends on Figure 11.20 is an implementation using AND, OR, and NOT gates the carry from the previous adder, there is an increasing delay from the least significant to the most significant bit Each single-bit adder experiences a certain amount of gate delay,A andBthis gate delay larger adders, A2 accumulates B2 AFor B A0 theB0accumulated 3 1 delay can become unacceptably high If the carry values could be determined without having to ripple through all Overflow the previous stages,Cthen each single-bit adder could CfunctionC independently, and C3 C2 Cin C1 Cin in in signal delay would not accumulate This can be achieved with an approach known as carry lookahead Let us look again at the 4-bit adder to explain this approach We would like to come up with an expression that specifies the carry input to any stage of theSadder without reference to previous carry values We have S S S ng A23 B23 A16 B16 du o A24 B24 C23 A15 B15 C15 8-bit adder A8 B8 A B7 C7 8-bit adder A0 B0 8-bit adder Cin cu u 8-bit adder Cout th Figure 11.19 4-Bit Adder A31 B31 an co ng c om Bộ cộng 4-bit cộng 32-bit S31 Figure 11.21 S24 S23 S16 S15 S8 S7 S0 Construction of a 32-Bit Adder Using 8-Bit Adders 2017 Kiến trúc máy tính CuuDuongThanCong.com 81 https://fb.com/tailieudientucntt NKK-HUST Mạch dãy mạch logic đầu phụ thuộc giá trị đầu vào thời điểm đầu vào thời điểm khứ co ng n c om 2.5 Mạch dãy an Là mạch có nhớ, thực phần tử nhớ (Latch, Flip-Flop) kết hợp với cổng logic cu u du o ng th n 2017 Kiến trúc máy tính CuuDuongThanCong.com 82 https://fb.com/tailieudientucntt NKK-HUST causing the output to be When both J and K are 1, the function performed is referred to as the toggle function: the output is reversed Thus, if Q is and is applied to J and K, then Q becomes The reader should verify that the implementation of Figure 11.26 produces this characteristic function Các Flip-Flop Graphical Symbol Q S R Qnϩ1 ng S Truth Table c om Name 0 1 1 Qn – Q J K Qnϩ1 K Q 0 1 1 Qn Qn D Q D Qnϩ1 1 Q th an R co Ck S–R ng J Ck cu u du o J–K D Ck Q 2017 Kiến trúc máy tính 83 Figure 11.27 Basic Flip-Flops CuuDuongThanCong.com https://fb.com/tailieudientucntt NKK-HUST S-R Latch Flip-Flop 11.4 / SEQUENTIAL CIRCUITS R 389 11.4 / SEQUENTIAL CIRCUITS R 11.4 / SEQUENTIAL CIRCUITS R 391 ng Q Clock c om Q co Q Figure 11.22 The S–R Latch Implemented with NOR Gates S-R Latch Q S Clocked S–R Flip-Flop S-R Flip-Flop CHAPTER 11 / DIGITAL LOGIC th 392 an Figure 11.24 Q Q S ClockS 391 Q cu u du o ng First, let us show that the circuit is bistable Assume that both S and R are Figure 11.24 Clocked S–R Flip-Flop and that Q is The inputs to the lower NOR gate are Q = and S = Thus, the Clock output Q = means that the inputs to the upper NOR gate are Q = and R = 0, Q K which has the output Q = Thus, the state of the circuit is internally consistent Q and remains stable as long as S = R = A similar line of reasoning shows that the Q state Q = 1, Q = is also stable for R = S = D Thus, this circuit can function as a 1-bit memory We can view the output Q as Clock Figure 11.25 D Flip-Flop Clock the “value” of the bit The inputs S and R serve to write the values and 0, respectively, into memory To see this, consider the state Q = 0, Q = 1, S = 0, R = This device is referred to as a clocked S–R flip-flop Note that the Suppose that S changes to the value Now the inputs to the lower NOR gatearrangement are Q R and S inputs are passed to the NOR gates only during the clock pulse S = 1, Q = After some time delay ^t, the output of the lower NOR gate will be J Q D Q = (see Figure 11.23) So, at this point in time, the inputs to the upper NORD gate FLIP-FLOP One problem with S–R flip-flop is that the condition R = 1, S = 11.25 Flip-Flop become R = 0,Figure Q = AfterDanother gate delay of ^t the output Q becomes must This be avoided One way to this is to allow just a single input The D flip-flop is again a stable state The inputs to the lower gate are now S = 1, Q = 1, which Figure 11.26 J–K Flip-Flop accomplishes this Figure 11.25 shows a gate implementation of the D flip-flop By maintain the output = As long as Sto=as1 aand R = 0, theflip-flop outputs will arrangement ThisQdevice is referred clocked S–R Noteremain that the using an inverter, the nonclock inputs to the two AND gates are guaranteed to be QR = and 1, QS=inputs Furthermore, if the S returns 0, the outputs unchanged are passed to NOR to gates only duringwill theremain clock pulse the opposite of each other The R output performs the opposite function When R goes to 1, it forces causing theDoutput to be 1; if only the K inputtoisas asserted, the result isbecause a reset function, flip-flop is sometimes referred the data flip-flop it is, in D FLIP-FLOP One problem with S–R flip-flop is that the condition R = 1, S = The Q = 0, Q = regardless of the previous state of Q and Q Again, a time delay of causing the output to be When both J and K are 1, the function performed effect, storage for one bit of data The output of the D flip-flop is always equal to the is must be avoided One way to this is to allow just a single input The D flip-flop 2^t occurs before the final state is established (Figure 11.23) referred to as the toggle function: the output is reversed Thus, if Q is and is applied mostBy recent value applied to the input Hence, it remembers and produces the last accomplishes this Figure 11.25 shows a gate implementation of the D flip-flop The S–R latch can be defined with a table similar to a truth table, called a to J and K,also thenreferred Q becomes The reader should verifyitthat theaimplementation using an inverter, the nonclock inputs to the two AND gates are guaranteed to beIt is input to as the delay flip-flop, because delays or applied toof characteristic table, which shows the next state or states of a sequential circuit as 11.26 Figure this characteristic 2017 Kiến the opposite of each other itstrúc inputmáy for produces atính single clock pulse We canfunction capture the logic of the D flip-flop in the84 a function of current states and inputs In the case of the S–R latch, the state can The D flip-flop is sometimes referred to as the data flip-flop because following it is, in truth table: be defined by the value of Q Table 11.10a shows the resulting characteristic table effect, storage for one bit of data The output of the D flip-flop is always equal to the Observe that the inputs S = 1, R = areCuuDuongThanCong.com not allowed, because these would prohttps://fb.com/tailieudientucntt D Q D Flip Flop J-K Flip-Flop NKK-HUST Thanh ghi 8-bit song song 393 Data lines D18 D16 D15 D14 D13 D12 D11 Q D D Clk Q D Q Clk Clk D Q D Clk Q D Clk Q D Clk Q Clk th Clk Q an D co ng D17 c om 11.4 / SEQUENTIAL CIRCUITS du o D07 D06 D05 D04 D03 D02 D01 Output lines u D08 ng Clock Load cu Figure 11.28 8-Bit Parallel Register Registers 2017 As an example of the use of flip-flops, let us first examine one of the essential elements of the CPU: the register As we know, a register is a digital circuit used within the CPU to store one or more bits of data Two basic types of registers are commonly used: parallel registers and registers Kiếnshift trúc máy tính PARALLELCuuDuongThanCong.com REGISTERS A parallel register consists of a set of 1-bit memories that https://fb.com/tailieudientucntt 85 so that data from a variety of sources can be loaded into the register SHIFT REGISTER A shift register accepts and/or transfers information serially NKK-HUST Consider, for example, Figure 11.29, which shows a 5-bit shift register constructed from clocked D flip-flops Data are input only to the leftmost flip-flop With each clock pulse, data are shifted to the right one position, and the rightmost bit is transferred out Shift registers can be used to interface to serial I/O devices In addition, they can be used within the ALU to perform logical shift and rotate functions In this Q D D Clk Q Clk D Q Clk D Q Serial out Clk th an Clk Q ng D co Serial in c om Thanh ghi dịch 5-bit ng Clock cu u du o Figure 11.29 5-Bit Shift Register 2017 Kiến trúc máy tính CuuDuongThanCong.com 86 https://fb.com/tailieudientucntt NKK-HUST because the change that occurs to increment the counter starts at one end and “ripples” through to the other end Figure 11.30 shows an implementation of a 4-bit counter using J–K flip-flops, together with a timing diagram that illustrates its behavior The timing diagram is idealized in that it does not show the propagation delay that occurs as the signals move down the series of flip-flops The output of the leftmost flip-flop (Q0) is the least significant bit The design could clearly be extended to an arbitrary number of bits by cascading more flip-flops Bộ đếm 4-bit Q J Ck Q K J Q K J Q1 K Q Ck Q K Q Q2 Q3 an Q0 Q Ck ng Ck Clock Q co J c om High th (a) Sequential circuit Q2 cu u Q1 du o Q0 ng Clock Q3 (b) Timing diagram Figure 11.30 Ripple Counter 2017 Kiến trúc máy tính CuuDuongThanCong.com 87 https://fb.com/tailieudientucntt co ng c om NKK-HUST cu u du o ng th an Hết chương 2017 Kiến trúc máy tính CuuDuongThanCong.com 88 https://fb.com/tailieudientucntt ... i=−m 20 17 Kiến trúc máy tính CuuDuongThanCong.com 53 https://fb.com/tailieudientucntt NKK-HUST Ví dụ số nhị phân c om 1101001.1011 (2) = -1 -2 -3 -4 + 2- 4 an co ng = 26 + 25 + 23 + 20 + 2- 1 + 2- 3... hợp bit: biểu diễn 25 6 giá trị (28 ) Qui ước đơn vị liệu: ng n 20 17 = 1 024 bytes = 22 0bytes (~106) = 23 0bytes (~109) = 24 0bytes (~10 12) = 25 0bytes = 26 0bytes Kiến trúc máy tính CuuDuongThanCong.com... 1101001 (2) 20 17 Kiến trúc máy tính CuuDuongThanCong.com 56 https://fb.com/tailieudientucntt NKK-HUST Phương pháp phân tích thành tổng 2i 23 128 64 32 16 1 an th 22 21 20 1 0 ng Kết quả: ng 24 co 25 105(10)

Ngày đăng: 07/06/2021, 16:50

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan