Thực hành Kiến trúc máy tính HUST

Mục tiêu: Học phần cung cấp cho sinh viên kiến thức nền tảng về kiến trúc tập lệnh và tổ chức của máy tính hiện đại, cũng như những vấn đề cơ bản trong thiết kế máy tính. Sau khi hoàn thành học phần này, sinh viên có khả năng tối ưu hóa trong lập trình phần mềm và tích hợp hệ thống để nâng cao hiệu năng, khai thác và quản trị hiệu quả các hệ thống máy tính.

Nội dung: Giới thiệu chung; Kiến trúc tập lệnh; Số học máy tính; Bộ xử lý, Bộ nhớ máy tính; Hệ thống vào-ra; Các kiến trúc máy tính song song.

Học phần tiên quyết: Không Học phần học trước:      - IT2110: Nhập môn CNTT và TT      - IT3210: Ngôn ngữ lập trình C Học phần song hành:      - IT3280: Thực hành kiến trúc máy tính

Thực hành Kiến trúc máy tính HUST

Biography of instructor/staff member #1

Thực hành Kiến trúc máy tính HUST

Biography of instructor/staff member #2

Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTTRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘIHanoi University of Science and TechnologyContact InformationnnKIẾN TRÚC MÁY TÍNHnComputer ArchitectureAddress: 502-B1Mobile: 091-358-5533e-mail: @hust.edu.vnNguyễn Kim KhánhBộ môn Kỹ thuật máy tínhViện Công nghệ thông tin và Truyền thôngDepartment of Computer Engineering (DCE)School of Information and Communication Technology (SoICT)Version: CA-20172017NKK-HUSTKiến trúc máy tínhNKK-HUSTMục tiêu học phầnnnTài liệu học tậpnSinh viên được trang bị các kiến thức cơ sở vềkiến trúc tập lệnh và tổ chức của máy tính, cũngnhư những nguyên tắc cơ bản trong thiết kếmáy tính.Sau khi học xong học phần này, sinh viên cókhả năng:nnnnn20172n[1] William StallingsComputer Organization and Architecture – 2013, 9th edition[2] David A. Patterson, John L. HennessyComputer Organization and Design – 2012, Revised 4th edition[3] David Money Harris, Sarah L. HarrisDigital Design and Computer Architecture – 2013, 2nd editionTìm hiểu kiến trúc tập lệnh của các bộ xử lý cụ thểLập trình hợp ngữĐánh giá hiệu năng máy tính và cải thiện hiệu năngcủa chương trìnhKhai thác và quản trị hiệu quả các hệ thống máy tínhPhân tích và thiết kế máy tínhKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTBài giảng Kiến trúc máy tínhftp://dce.soict.hust.edu.vn/khanhnk/CA/Sách tham khảo:[4] Andrew S. TanenbaumStructured Computer Organization – 2013, 6th editionnPhần mềm lập trình hợp ngữ và mô phỏng cho MIPS:MARS (MIPS Assembler and Runtime Simulator)download tại: http://courses.missouristate.edu/KenVollmar/MARS/32017Kiến trúc máy tính41Bài giảng Kiến trúc máy tínhCA-20172NKK-HUST2017NKK-HUSTNội dung học phầnContentChương 1. Giới thiệu chungChương 2. Cơ bản về logic sốChương 3. Hệ thống máy tínhChương 4. Số học máy tínhChương 5. Kiến trúc tập lệnhChương 6. Bộ xử lýChương 7. Bộ nhớ máy tínhChương 8. Hệ thống vào-raChương 9. Các kiến trúc song songChapter 1. IntroductionChapter 2. The Basics of Digital LogicChapter 3. Computer SystemsChapter 4. Computer ArithmeticChapter 5. Instruction Set ArchitectureChapter 6. The ProcessorsChapter 7. Computer MemoryChapter 8. Input-Output SystemsChapter 9. Parallel ArchitecturesKiến trúc máy tính5NKK-HUST2017Kiến trúc máy tính6NKK-HUSTKiến trúc máy tínhNội dung của chương 11.1. Máy tính và phân loại máy tính1.2. Khái niệm kiến trúc máy tính1.3. Sự tiến hóa của công nghệ máy tính1.4. Hiệu năng máy tínhChương 1GIỚI THIỆU CHUNGNguyễn Kim KhánhTrường Đại học Bách khoa Hà Nội2017Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST72017Kiến trúc máy tính82Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUST1.1. Máy tính và phân loại máy tínhnMô hình đơn giản của máy tínhMáy tính (Computer) là thiết bị điện tử thựchiện các công việc sau:nnnxử lý dữ liệuNhận dữ liệu vào,Xử lý dữ liệu theo dãy các lệnh được nhớ sẵn bêntrong,Đưa dữ liệu (thông tin) ra.Cácthiết bị vào(InputDevices)Dãy các lệnh nằm trong bộ nhớ để yêu cầumáy tính thực hiện công việc cụ thể gọi làchương trình (program).à Máy tính hoạt động theo chương trìnhn2017Kiến trúc máy tínhdữ liệu vào92017nDesktop computers, Laptop computersMáy tính đa dụngnnThiết bị di động cá nhân (PMD - Personal MobileDevices)nMáy chủ (Servers) – máy phục vụnnDùng trong mạng để quản lý và cung cấp các dịch vụHiệu năng và độ tin cậy caoHàng nghìn đến hàng triệu USDnnnnDùng cho tính toán cao cấp trong khoa học và kỹ thuậtHàng triệu đến hàng trăm triệu USDnMáy tính nhúng (Embedded Computers)nnĐặt ẩn trong thiết bị khácĐược thiết kế chuyên dụngKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTn112017Smartphones, TabletKết nối InternetĐiện toán đám mây (Cloud Computing)Siêu máy tính (Supercomputers)n201710Phân loại máy tính kỷ nguyên sau PCMáy tính cá nhân (Personal Computers)nndữ liệu raNKK-HUSTnnchương trìnhđang thực hiệnKiến trúc máy tínhPhân loại máy tính kỷ nguyên PCnCácthiết bị ra(OutputDevices)Bộ nhớ chính(Main Memory)NKK-HUSTnBộ xử lýtrung tâm(CentralProcessing Unit)Sử dụng máy tính qui mô lớn (Warehouse ScaleComputers), gồm rất nhiều servers kết nối với nhauCho các công ty thuê một phần để cung cấp dịch vụphần mềmSoftware as a Service (SaaS): một phần của phầnmềm chạy trên PMD, một phần chạy trên CloudVí dụ: Amazon, GoogleKiến trúc máy tính123Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUST1.2. Khái niệm kiến trúc máy tínhnKiến trúc máy tính bao gồm:nnnnPhân lớp máy tínhKiến trúc tập lệnh (Instruction Set Architecture):nghiên cứu máy tính theo cách nhìn của người lậptrìnhNgườisử dụngTổ chức máy tính (Computer Organization) hayVi kiến trúc (Microarchitecture): nghiên cứu thiết kếmáy tính ở mức cao (thiết kế CPU, hệ thống nhớ,cấu trúc bus, ...)NKK-HUST13Ngôn ngữ bậc caoHợp ngữnnnAssembly languageMô tả lệnh dưới dạng textnnKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTLập lịch cho các nhiệm vụ và chia sẻ tàinguyênnQuản lý bộ nhớ và lưu trữnĐiều khiển vào-raPhần cứng2017Bộ xử lý, bộ nhớ, mô-đun vào-raKiến trúc máy tínhNKK-HUSTCác thành phần cơ bản của máy tínhnlanguage such as C, Cϩϩ,Java, or Visual Basic thatis composed of wordsand algebraic notationthat can be translated bya compiler into assemblylanguage.nCPUBộ nhớ chínhGiống nhau với tất cả các loạimáy tínhBộ xử lý trung tâm (CentralProcessing Unit – CPU)nAssemblylanguageprogram(for MIPS)swap:multiaddlwlwswswjr$2, $5,4$2, $4,$2$15, 0($2)$16, 4($2)$16, 0($2)$15, 4($2)$31Bus hệ thốngnnn2017Trao đổi thông tin giữa máy tínhvới bên ngoàiBus hệ thống (System bus)n15FIGURE 1.4 C program compiled into assembly language and then assembled into binarymachine language. Although the translation from high-level language to binary machine language isshown in two steps, some compilers cut out the middleman and produce binary machine language directly.These languages and this program are examined in more detail in Chapter 2.Chứa các chương trình đangthực hiệnHệ thống vào-ra (Input/Output)n00000000101000100000000100011000000000001000001000010000001000011000110111100010000000000000000010001110000100100000000000000100101011100001001000000000000000001010110111100010000000000000010000000011111000000000000000001000Điều khiển hoạt động của máytính và xử lý dữ liệuBộ nhớ chính (Main Memory)nAssemblerBinary machinelanguageprogram(for MIPS)1415Hệ thống vào-raMachine languageMô tả theo phần cứngCác lệnh và dữ liệu đượcmã hóa theo nhị phânHệ điều hành (Operating System)Phần cứnghigh-levelprogramminglanguage A portableswap(int v[], int k){int temp;temp = v[k];v[k] = v[k+1];v[k+1] = temp;}Chương trình dịch (Compiler): dịch mãngôn ngữ bậc cao thành ngôn ngữ máynCompilerNgôn ngữ máyn2017High-level language – HLLMức trừu tượng gần vớivấn đề cần giải quyếtHiệu quả và linh độngHigh-levellanguageprogram(in C)Được viết theo ngôn ngữ bậc caoPhần mềm hệ thốngCác mức của mã chương trìnhnnnThe recognition that a program could be written to translate a more powerfullanguage into computer instructions was one of the great breakthroughs in theearly days of computing. Programmers today owe their productivity—and theirsanity—to the creation of high-level programming languages and compilersthat translate programs in such languages into instructions. Figure 1.4 shows therelationships among these programs and languages, which are more examples ofthe power of abstraction.nNgườilập trìnhhệ thốngn1.3 Below Your ProgramnPhần mềm hệ thốngCùng một kiến trúc tập lệnh có thể có nhiều sảnphẩm (tổ chức, phần cứng) khác nhauKiến trúc máy tínhnnnPhần cứng (Hardware): nghiên cứu thiết kế logic chitiết và công nghệ đóng gói của máy tính.2017nPhần mềm ứng dụngnNgườilập trìnhPhần mềm ứng dụngnKết nối và vận chuyển thông tinKiến trúc máy tính164Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUST1.3. Sự tiến hóa của công nghệ máy tínhnMáy tính dùng đèn điện tử chân không (1950s)nnnnnnSSI - Small Scale IntegrationMSI - Medium Scale IntegrationLSI - Large Scale IntegrationnMáy tính dùng vi mạch VLSI (1980s)nnMáy tính ENIAC: máy tính đầu tiên (1946)Máy tính IAS: máy tính von Neumann (1952)Máy tính dùng transistors (1960s)Máy tính dùng vi mạch SSI, MSI và LSI (1970s)nnMáy tính đầu tiên: ENIAC và IASnVLSI - Very Large Scale IntegrationnMáy tính dùng vi mạch ULSI (1990s-nay)nnULSI - Ultra Large Scale Integration2017nKiến trúc máy tính17NKK-HUSTElectronic Numerical Intergatorand ComputerDự án của Bộ Quốc phòng MỹDo John Mauchly ở đại họcPennsylvania thiết kế30 tấnXử lý theo số thập phân2017nnnThực hiện tại Princeton Institutefor Advanced StudiesDo John von Neumann thiết kếtheo ý tưởng “stored program”Xử lý theo số nhị phânTrở thành mô hình cơ bản củamáy tínhKiến trúc máy tính18NKK-HUSTMáy tính ngày nayMột số loại vi mạch số điển hìnhMassive ClusterGigabit EthernetnBộ vi xử lý (Microprocessors)nVi mạch điều khiển tổng hợp (Chipset)nClustersnnRefrigeratorsSensorNetsnnnRoutersRoutersKiến trúc máy tínhNguyễn Kim Khánh DCE-HUST192017Vi mạch thực hiện các chức năng nối ghép các thànhphần của máy tính với nhauROM, RAM, Flash memoryHệ thống trên chip (SoC – System on Chip) hayBộ vi điều khiển (Microcontrollers)nRobotsRobotsMột hoặc một vài CPU được chế tạo trên một chipBộ nhớ bán dẫn (Semiconductor Memory)Cars2017nTích hợp các thành phần chính của máy tính trên mộtchip vi mạchĐược sử dụng chủ yếu trên smartphone, tablet và cácmáy tính nhúngKiến trúc máy tính205Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTSự phát triển của bộ vi xử lýnnn1971: bộ vi xử lý 4-bit Intel 40041972: các bộ xử lý 8-bit1978: các bộ xử lý 16-bitnnnn1.4. Hiệu năng máy tínhHiệu năng = 1/(thời gian thực hiện)hay là: P = 1/tMáy tính cá nhân IBM-PC ra đời năm 1981“Máy tính A nhanh hơn máy B k lần”1985: các bộ xử lý 32-bit2001: các bộ xử lý 64-bit2006: các bộ xử lý đa lõi (multicores)nĐịnh nghĩa hiệu năng P (Performance):nPA / PB = tB / tA = kVí dụ: Thời gian chạy chương trình:nNhiều CPU trên 1 chipnnn2017Kiến trúc máy tính21NKK-HUST2017Kiến trúc máy tínhThời gian thực hiện của CPUVề mặt thời gian, CPU hoạt động theo một xung nhịp(clock) có tốc độ xác địnhnnn2017Chu kỳ xung nhịp T0 (Clock period): thời gian của mộtchu kỳTốc độ xung nhịp f0 (Clock rate) hay là Tần số xung nhịp:số chu kỳ trong 1sn f0 = 1/T0VD: Bộ xử lý có f0 = 4GHz = 4×109HzT0 = 1/(4x109) = 0.25x10–9s = 0.25nsKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTĐể đơn giản, ta xét thời gian CPU thực hiệnchương trình (CPU time):Thời gian thực hiện của CPU =Số chu kỳ xung nhịp x Thời gian một chu kỳT0n22NKK-HUSTTốc độ xung nhịp của CPUn10s trên máy A, 15s trên máy BtB / tA = 15s / 10s = 1.5Vậy máy A nhanh hơn máy B 1.5 lầntCPU = n × T0 =nf0n: số chu kỳ xung nhịpnHiệu năng được tăng lên bằng cách:nn232017Giảm số chu kỳ xung nhịp nTăng tốc độ xung nhịp f0Kiến trúc máy tính246Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTVí dụnnHai máy tính A và B cùng chạy một chương trìnhMáy tính A:nnnTa có:Tốc độ xung nhịp của CPU: fA = 2GHzThời gian CPU thực hiện chương trình: tA = 10st=nnfSố chu kỳ xung nhịp khi chạy chương trình trên máy A:nA = t A × f A = 10s × 2GHz = 20 ×10 9Máy tính B:nnVí dụ (tiếp)Thời gian CPU thực hiện chương trình: tB = 6sSố chu kỳ xung nhịp khi chạy chương trình trên máy B (nB) nhiềuhơn 1.2 lần số chu kỳ xung nhịp khi chạy chương trình trên máyA (nA)Số chu kỳ xung nhịp khi chạy chương trình trên máy B:nB = 1.2 × nA = 24 ×10 9Hãy xác định tốc độ xung nhịp cần thiết cho máy B (fB)?Tốc độ xung nhịp cần thiết cho máy B:fB =2017Kiến trúc máy tính25NKK-HUSTnB 24 ×10 9== 4 ×10 9 Hz = 4GHztB62017Kiến trúc máy tính26NKK-HUSTSố lệnh và số chu kỳ trên một lệnhVí dụSố chu kỳ xung nhịp của chương trình:nSố chu kỳ = Số lệnh của chương trình x Số chu kỳ trên một lệnhnn = IC × CPInnnnn - số chu kỳ xung nhịpIC - số lệnh của chương trình (Instruction Count)CPI - số chu kỳ trên một lệnh (Cycles per Instruction)nnnnIC × CPIf0Chu kỳ xung nhịp: TA = 250psSố chu kỳ/ lệnh trung bình: CPIA = 2.0Máy tính B:nVậy thời gian thực hiện của CPU:tCPU = IC × CPI × T0 =Hai máy tính A và B có cùng kiến trúc tập lệnhMáy tính A có:Chu kỳ xung nhịp: TB = 500psSố chu kỳ/ lệnh trung bình: CPIB = 1.2Hãy xác định máy nào nhanh hơn và nhanh hơnbao nhiêu ?Trong trường hợp các lệnh khác nhau có CPI khác nhau,cần tính CPI trung bình2017Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST272017Kiến trúc máy tính287Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTVí dụ (tiếp)Ta có:CPI trung bìnhtCPU = IC × CPITB × T0nHai máy cùng kiến trúc tập lệnh, vì vậy số lệnh của cùngmột chương trình trên hai máy là bằng nhau:Nếu loại lệnh khác nhau có số chu kỳ khác nhau,ta có tổng số chu kỳ:KICA = ICB = ICn = ∑ (CPI i × ICi )Thời gian thực hiện chương trình đó trên máy A và máy B:i=1t A = ICA × CPI A × TA = IC × 2.0 × 250 ps = IC × 500 psnCPI trung bình:t B = ICB × CPI B × TB = IC ×1.2 × 500 ps = IC × 600 psTừ đó ta có:CPITB =t B IC × 600 ps== 1.2t A IC × 500 psn1 K= ∑ (CPI i × ICi )IC IC i=1Kết luận: máy A nhanh hơn máy B 1.2 lần2017Kiến trúc máy tính29NKK-HUST2017Kiến trúc máy tínhNKK-HUSTVí dụnVí dụCho bảng chỉ ra các dãy lệnh sử dụng các lệnhthuộc các loại A, B, C. Tính CPI trung bình?nCho bảng chỉ ra các dãy lệnh sử dụng các lệnhthuộc các loại A, B, C. Tính CPI trung bình?Loại lệnhABCLoại lệnhABCPI theo loại lệnh123CPI theo loại lệnh123IC trong dãy lệnh 1201020IC trong dãy lệnh 1201020IC trong dãy lệnh 2401010IC trong dãy lệnh 2401010nDãy lệnh 1: Số lệnh = 50nSố chu kỳ == 1x20 + 2x10 + 3x20 = 100n CPITB = 100/50 = 2.0n201730Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST312017Kiến trúc máy tínhCDãy lệnh 2: Số lệnh = 60Số chu kỳ == 1x40 + 2x10 + 3x10 = 90n CPITB = 90/60 = 1.5n328Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTMIPS như là thước đo hiệu năngTóm tắt về Hiệu năngCPU Time =Instructions Clock cycles Seconds´´ProgramInstruction Clock cyclenMIPS: Millions of Instructions Per Second(Số triệu lệnh trên 1 giây)Thời gian CPU = Số lệnh của chương trình x Số chu kỳ/lệnhx Số giây của một chu kỳtCPUnMIPS =IC × CPI= IC × CPI × T0 =f0Instruction countInstruction countClock rate==Execution time ×106 Instruction count × CPI ×106 CPI×106Clock rateHiệu năng phụ thuộc vào:nnnnnMIPS =Thuật giảiNgôn ngữ lập trìnhChương trình dịchKiến trúc tập lệnhPhần cứng2017Kiến trúc máy tính33NKK-HUSTf0CPI ´ 10 62017CPI =f0MIPS ´ 10 6Kiến trúc máy tính34NKK-HUSTVí dụVí dụTính MIPS của bộ xử lý với:clock rate = 2GHz và CPI = 4Tính MIPS của bộ xử lý với:clock rate = 2GHz và CPI = 40.5ns2ns§§§§2017Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST352017Chu kỳ T0 = 1/(2x109) = 0.5nsCPI = 4 à thời gian thực hiện 1 lệnh = 4 x 0.5ns = 2nsSố lệnh thực hiện trong 1s = (109ns)/(2ns) = 5x108 lệnhVậy bộ xử lý thực hiện được 500 MIPSKiến trúc máy tính369Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTVí dụVí dụTính CPI của bộ xử lý với:clock rate = 1GHz và 400 MIPSTính CPI của bộ xử lý với:clock rate = 1GHz và 400 MIPS1ns§§§§2017Kiến trúc máy tính37NKK-HUST2017Kiến trúc máy tính38NKK-HUSTCác ý tưởng tuyệt vời trong kiến trúc máy tínhMFLOPS1. Design for Moore’s LawThiết kế theo luật Moore2. Use abstraction to simplify designSử dụng trừu tượng hóa để đơn giản thiết kế3. Make the common case fastLàm cho các trường hợp phổ biến thực hiện nhanh4. Performance via parallelismTăng hiệu năng qua xử lý song song5. Performance via pipeliningTăng hiệu năng qua kỹ thuật đường ống6. Performance via predictionTăng hiệu năng thông qua dự đoán7. Hierarchy of memoriesPhân cấp bộ nhớ8. Dependability via redundancyTăng độ tin cậy thông qua dự phòng§ Sử dụng cho các hệ thống tính toán lớn§ Millions of Floating Point Operations per Second§ Số triệu phép toán số dấu phẩy động trên một giâyMFLOPS =Executed floating point operationsExecution time ×106GFLOPS(109 )TFLOPS(1012)PFLOPS (1015)2017Chu kỳ T0 = 1/109 = 1nsSố lệnh thực hiện trong 1 s là 400MIPS = 4x108 lệnhThời gian thực hiện 1 lệnh = 1/(4x108)s = 2.5nsVậy ta có: CPI = 2.5Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST392017Kiến trúc máy tính4010Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTKiến trúc máy tínhChương 2CƠ BẢN VỀ LOGIC SỐHết chương 1Nguyễn Kim KhánhTrường Đại học Bách khoa Hà Nội2017Kiến trúc máy tính41NKK-HUST201742NKK-HUSTNội dung của chương 2Nội dung học phầnChương 1. Giới thiệu chungChương 2. Cơ bản về logic sốChương 3. Hệ thống máy tínhChương 4. Số học máy tínhChương 5. Kiến trúc tập lệnhChương 6. Bộ xử lýChương 7. Bộ nhớ máy tínhChương 8. Hệ thống vào-raChương 9. Các kiến trúc song song2017Kiến trúc máy tínhKiến trúc máy tínhNguyễn Kim Khánh DCE-HUST2.1. Các hệ đếm cơ bản2.2. Đại số Boole2.3. Các cổng logic2.4. Mạch tổ hợp2.5. Mạch dãy432017Kiến trúc máy tính4411Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUST2.1. Các hệ đếm cơ bảnnnn20171. Hệ thập phânHệ thập phân (Decimal System)à con người sử dụngHệ nhị phân (Binary System)à máy tính sử dụngHệ mười sáu (Hexadecimal System)à dùng để viết gọn cho số nhị phânKiến trúc máy tínhCơ số 10n10 chữ số: 0,1,2,3,4,5,6,7,8,9Dùng n chữ số thập phân có thể biểu diễnđược 10n giá trị khác nhau:n45NKK-HUSTn00...000= 0n99...999= 10n - 12017Kiến trúc máy tính46NKK-HUSTDạng tổng quát của số thập phânVí dụ số thập phânA = an an-1 ... a1a0 , a-1 ... a-m472.38 = 4x102 + 7x101 + 2x100 + 3x10-1 + 8x10-2nGiá trị của A được hiểu như sau:A = an10 n + an−110 n−1 +... + a1101 + a010 0 + a−110 −1 +... + a−m10 −mnA=∑ a 10inKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTCác chữ số của phần nguyên:n472 : 10 = 47 dư2n47 : 10 = 4 dư7n4 : 10 = 0 dư4Các chữ số của phần lẻ:ii=−m2017n472017n0.38 x 10 = 3.8 phần nguyên =3n0.8 x 10 = 8.0 phần nguyên =8Kiến trúc máy tính4812Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTSố nhịphân2. Hệ nhị phânnnnnnCơ số 22 chữ số nhị phân: 0 và 1Chữ số nhị phân được gọi là bit (binary digit)bit là đơn vị thông tin nhỏ nhấtDùng n bit có thể biểu diễn được 2n giá trị khácnhau:nnn00...00011...111Biểu diễnsố nhị phân2-bit3-bit4-bitSốthậpphân0000000000010100100011100100010211011001131000100410101015110011061110111710008= 0= 2n - 1Các lệnh của chương trình và dữ liệu trongmáy tính đều được mã hóa bằng số nhị phân2017Kiến trúc máy tính49NKK-HUST2017Kiến trúc máy tính1001910101010111111001211011311101411111550NKK-HUSTĐơn vị dữ liệu và thông tin trong máy tínhnnnQui ước mới về ký hiệu đơn vị dữ liệubit – chữ số nhị phân (binary digit): là đơn vị thôngtin nhỏ nhất, cho phép nhận một trong hai giá trị: 0hoặc 1.byte là một tổ hợp 8 bit: có thể biểu diễn được 256giá trị (28)Qui ước các đơn vị dữ liệu:nnnnnn20171-bitKB (Kilobyte)MB (Megabyte)GB (Gigabyte)TB (Terabyte)PB (Petabyte)EB (Exabyte)= 210 bytes= 210 KB= 210 MB= 210 GB= 210 TB= 210 PBKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTTheothập phân= 1024 bytes= 220bytes (~106)= 230bytes (~109)= 240bytes (~1012)= 250bytes= 260bytesViết tắtGiá trịĐơn vịViết tắtGiá trịkilobyteKB103kibibyteKiB210 =1024megabyteMB106mebibyteMiB220gigabyteGB109gibibyteGiB230TB1012tebibyteTiB240petabytePB1015pebibytePiB250exabyteEB1018exbibyteEiB260terabyte512017Theonhị phânĐơn vịKiến trúc máy tính5213Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTDạng tổng quát của số nhị phânA = an an−1 ... a1a0 , a−1 ... a−mVí dụ số nhị phân1101001.1011(2) =với ai=0 hoặc 16 5 4 3 2 1 0= 26 + 25 + 23 + 20 + 2-1 + 2-3Giá trị của A được tính như sau:2-4= 105.6875(10)n∑a2+= 64 + 32 + 8 + 1 + 0.5 + 0.125 + 0.0625A = an 2 n + an−1 2 n−1 +... + a1 21 + a0 2 0 + a−1 2 −1 +... + a−m 2 −mA=-1 -2 -3 -4iii=−m2017Kiến trúc máy tính53NKK-HUST2017Kiến trúc máy tínhNKK-HUSTChuyển đổi số nguyên thập phân sang nhị phânPhương pháp chia dần cho 2nnnPhương pháp 1: chia dần cho 2 rồi lấyphần dưPhương pháp 2: Phân tích thành tổngcủa các số 2i à nhanh hơnn201754Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST552017Ví dụ: chuyển đổi 105(10)n105 : 2 =52dư1n52 : 2 =26dư0n26 : 2 =13dư0n13 : 2 =6dư1n6:2 =3dư0n3:2 =1dư1n1:2 =0dư1biểu diễnsố dưtheo chiềumũi tênKết quả: 105(10) = 1101001(2)Kiến trúc máy tính5614Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTChuyển đổi số lẻ thập phân sang nhị phânPhương pháp phân tích thành tổng của các 2iVí dụ 1: chuyển đổi 105(10)6530n 105 = 64 + 32 + 8 +1 = 2 + 2 + 2 + 2nn0.6875 x 2 = 1.375phần nguyên = 11n0.375 x 2 = 0.75phần nguyên = 01n0.75x 2 = 1.5phần nguyên = 1n0.5x 2 = 1.0phần nguyên = 1262524232221201286432168420110100105(10) = 0110 1001(2)Ví dụ 2: 17000(10) = 16384 + 512 + 64 + 32 + 8n=Ví dụ 1: chuyển đổi 0.6875(10)n27Kết quả:nn214 + 29 + 26 + 25 + 23biểu diễntheochiềumũi tênKết quả : 0.6875(10)= 0.1011(2)17000(10) = 0100 0010 0110 1000(2)15 14 13 12 11 10 9 820177 6 5 43 2 1 0Kiến trúc máy tính57NKK-HUST2017Kiến trúc máy tínhNKK-HUST3. Hệ mười sáu (Hexa)Chuyển đổi số lẻ thập phân sang nhị phân (tiếp)nn201758Ví dụ 2: chuyển đổi 0.81(10)n0.81 x 2 =1.62phần nguyên=1n0.62 x 2 =1.24phần nguyên=1n0.24 x 2 =0.48phần nguyên=0n0.48 x 2 =0.96phần nguyên=0n0.96 x 2 =1.92phần nguyên=1n0.92 x 2 =1.84phần nguyên=1n0.84 x 2 =1.68phần nguyên=1nCơ số 16n16 chữ số: 0,1,2,3,4,5,6,7,8,9, A,B,C,D,E,FnDùng để viết gọn cho số nhị phân: cứ mộtnhóm 4-bit sẽ được thay bằng một chữ sốHexa0.81(10) » 0.1100111(2)Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST592017Kiến trúc máy tính6015Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTQuan hệ giữa số nhị phân và số HexaVídụ:n10110011(2) =B3(16)n00000000(2) =00(16)n0010110110011010(2)=2D9A(16)n1111111111111111(2)=FFFF(16)2017Kiến trúc máy tính2.2. Đại số Boole4-bitSố HexaThậpphân000000000111n001022n0011330100440101550110660111771000881001991010A101011B111100C121101D131110E141111F15nn61NKK-HUSTnA AND B :nA OR B :A • B hay ABA+BnNOT A :An Thứ tự ưu tiên: NOT > AND > ORThêm các phép toán logic: NAND, NOR, XORnA NAND B:nA NOR B :nA XOR B:A•BA+ BAÅ B = A• B + A• B2017Kiến trúc máy tính62NKK-HUSTCác đồng nhất thức của đại số BoolePhép toán đại số Boole với hai biến2017Đại số Boole sử dụng các biến logic và phép toán logicBiến logic có thể nhận giá trị 1 (TRUE) hoặc 0 (FALSE)Các phép toán logic cơ bản: AND, OR và NOTABAANDBA•BABAORBA+BA000000010011100101111111ANANDBAB100110011101AB00011A•BANORBAA•B=B•AA+B=B+A01A • (B + C) = (A • B) + (A • C)A + (B • C) = (A + B) • ( A + C)101•A=A0+A=AA•A=0A+A=10•A=01+A=1A•A=AA+A=ANOT là phép toán 1 biếnAXORBAB1000A • (B • C) = (A • B) • CA + (B + C) = (A + B) + C10011A • B = A + B (Định lý De Morgan)A + B = A • B (Định lý De Morgan)0010110110A+BKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTNOTAAÅ B632017Kiến trúc máy tính6416Bài giảng Kiến trúc máy tínhNKK-HUSTNKK-HUSTThực hiện các hàm logic:nnnnNOT, AND, OR, NAND, NOR, XORCổng NOTFANANDCổng nhiều đầu vàoKiến trúc máy tínhFϭA•BorF ϭ AB369type of electronic circuitry.A FFϭATypically,not allA gate types areused in implementation.and fabrication0 Design1NOTForare simpler if only one or two types of gates areThus, 1it is0 important to identifyF ϭ used.AЈfunctionally complete sets of gates. This means that any Boolean function can be impleA B Fmented using only the gates in the set. The following are functionallycomplete sets:0 0 1AND, OR, XOR, NAND, NOR2017Truth TableA B F0 0 00 1 0B1 0 0 11.2 / GATES1 1 1A B FHere we introduceacommonterm:wesaythattoassert0 0 0a signal is to cause aAF ϭ A ϩ Bfalse (0) 0stateF its logically1 1 to its logically truesignal line toORmake aBtransition from1 0 1(1) state. The true (1) state is either a high or low voltage1 state,1 1 depending on theAANDCổng hai đầu vào:nAlgebraicFunctionGraphical SymbolNameCổng logic một đầu vào:nCA-20172Ký hiệu các cổng logic2.3. Các cổng logic (Logic Gates)ntions are implemented by the interconnection of gates.A gate is an electronic circuit that produces an output signal that is a simple Boolean operation on its input signals. The basic gates used in digital logic areAND, OR, NOT, NAND, NOR, and XOR. Figure 11.1 depicts these six gates. Eachgate is defined in three ways: graphic symbol, algebraic notation, and truth table.The symbology used in this chapter is from the IEEE standard, IEEE Std 91. Notethat the inversion (NOT) operation is indicated by a circle.Each gate shown in Figure 11.1 has one or two inputs and one output.However, as indicated in Table 11.1b, all of the gates except NOT can have morethan two inputs. Thus, (X + Y + Z) can be implemented with a single OR gatewith three inputs. When one or more of the values at the input are changed, thecorrect output signal appears almost instantaneously, delayed only by the propagation time of signals through the gate (known as the gate delay). The significance ofthis delay is discussed in Section 11.3. In some cases, a gate is implemented with twooutputs, one output being the negation of the other output.F ϭ ABF0 1 11 0 11 1 0A B F0 0 1AFϭAϩB0 1 0NORFB1 0 0• NAND1 1 0• NORA B F0 0 0AXORbe clear that AND, FIt shouldOR, andaF ϭ NOTA  B gates constitute0 1 1B1complete set, because they represent the three operations1of0 BooleanKiến trúc máy tính1 1 0B• AND, OR, NOT• AND, NOT• OR, NOT652017functionallyalgebra. Forthe AND and NOT gates to form a functionally complete set, there must be a wayFigure11.1ORBasicLogic Gatesto synthesizetheoperationfrom the AND and NOT operations. This can bedone by applying DeMorgan’s theorem:66A + B = A#BA OR B = NOT ((NOT A) AND (NOT B))NKK-HUSTNKK-HUSTTập đầy đủnnSử dụng cổng NANDLà tập các cổng có thể thực hiện được bất kỳhàm logic nào từ các cổng của tập đóMột số ví dụ về tập đầy đủ:n{AND, OR, NOT}n{AND, NOT}n{OR, NOT}n{NAND}n{NOR}Similarly, the OR and NOT operations are functionally complete becausethey can be used to synthesize the AND operation.Figure 11.2 shows how the AND, OR, and NOT functions can be implementedsolely with NAND gates, and Figure 11.3 shows the same thing for NOR gates.For this reason, digital circuits can be, and frequently are, implemented solely withNAND gates or solely with NOR gates.AAAA BBAA BAA+BBBFigure 11.2 Some Uses of NAND Gates2017Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST672017Kiến trúc máy tính6817Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTSử dụng cổng NOR370Một số vi mạch logicCHAPTER 11 / DIGITAL LOGIC1AA1BA1Y2A(A+B)AB2BA+B2YGND1A1BA B1Y2AB2BB2YFigure 11.3 Some Uses of NOR GatesGNDWith gates, we have reached the most primitive circuit level of computerhardware. An examination of the transistorcombinations used to construct gatesKiến trúc máy tínhdeparts from that realm and enters the realm of electrical engineering. For our purposes, however, we are content to describe how gates can be used as building blocksto implement the essential logical circuits of a digital computer.6920171A1BNC1C11.3 COMBINATIONAL CIRCUITS1DNKK-HUSTA combinational circuit is an interconnected set of gates whose output at any timeis a function only of the input at that time. As with a single gate, the appearance ofthe input is followed almost immediately by the appearance of the output, with onlygate delays.nIn general terms, a combinational circuit consists of n binary inputs and mbinary outputs. As with a gate, a combinational circuit can be defined in three ways:NKK-HUST••n•nnCác đầu vào (Inputs)Truth table: For each of the 2 n possible combinations of input signals, theCác valueđầuofraeach(Outputs)binaryof the m output signals is listed.GraphicalThe interconnectedlayoutspecification)of gates is depicted.Đặc tả symbols:chức năng(FunctionalBoolean equations: Each output signal is expressed as a Boolean function ofĐặcthời gian (Timing specification)itsinputtảsignals.nnCác kiểu mạch logic:Anycan(Combinationalbe implemented in electronicform as a network of gates.n BooleanMạchfunctiontổ hợpCircuits)For any given function, there are a number of alternative realizations. Consider then Mạch không nhớBoolean function represented by the truth table in Table 11.3. We can express this function by simplyitemizingthe combinationsof valuesof A,and CcauseF tobe 1:n Đầura đượcxác định bởicác giátrịB,hiệntạithatcủađầuvàoABC + ABCF + ABC +Circuits)Mạch dãy (Sequentialnn20171331241151069787400 NANDVDD1Y4B1A4A1B4Y2Y3B2A3A2B3YGND11421331241151069787402 NORVDD1A4Y1Y4B2A4A2Y3Y3A3B3Y3AGND11421331241151069787404 NOTVDD6A6Y5A5Y4A4Y11421331241151069787408 AND1142133124115106978VDD1A4B1B4A2A4Y2B3B2C3A2Y3YGNDVDD1CLR7421 AND411421331241151069787411 AND3VDD1A1C1B1Y1Y3C2A3B2B3A2Y3YGNDKiến trúc máy tính2D1D2C1CLKNC1PRE2B1Q2A1Q2YGND12341413resetD QQsetresetQ DQset512111069787474 FLOPVDD1A2CLR1B2D1Y2CLK2A2PRE2B2Q2Y2QGND11421331241151069787432 OR11421331241151069787486 XORVDD4B4A4Y3B3A3Y70VDD4B4A4Y3B3A3YFigure A.1 Common 74xx-series logic gatesn Implementation of Boolean Functionsn142Mạch tổ hợpMạch logic là mạch bao gồm:n1YGND2.4. Mạch tổ hợpn1AA2017585A.3 Programmable LogicMạch tổ hợp là mạch logic trong đó đầu ra chỉphụ thuộc đầu vào ở thời điểm hiện tạiLà mạch không nhớ và được thực hiện bằngcác cổng logicMạch tổ hợp có thể được định nghĩa theo bacách:nn(11.1)nBảng thật (True Table)Dạng sơ đồPhương trình BooleMạch có nhớĐầu ra được xác định bởi các giá trị trước đó và giá trị hiện tạicủa đầu vàoKiến trúc máy tínhNguyễn Kim Khánh DCE-HUST712017Kiến trúc máy tính72181Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTBộ chọn kênh (Multiplexer - MUX)This can be rewritten using a generalization of DeMorgan’s theorem:(X # Y # Z) = X + Y + ZCHAPTER 11 / DIGITAL LOGICĐầuvàoA0F = 1A B C2 # 1A B C2 # 1A B C2 # 1A B C2 # 1A B C2Ví dụAB1There are three combinations of input values that cause F to be 1, and if anyone of these combinations occurs, the result is 1. This form of expression, for selfevident reasons, is known as the sum of products (SOP) form. Figure 11.4 shows astraightforward implementation with AND, OR, and NOT gates.Another form can also be derived from the truth table. The SOP formexpresses that the output is 1 if any of the input combinations that produce 1 is true.We can also say that the output is 1 if none of the input combinations that produce0 is true. Thus,NKK-HUST3801ĐầuraBCABCnF0000 F0010BC0101Figure 11.11NANDImplementation0111 ofFTable 11.3100011.3 / COMBINATIONAL CIRCUITS 381101 Another0 consideration in theNAND AND NOR IMPLEMENTATIONSTable 11.7 4-to-1 Multiplexer Truth Tableimplementation of Boolean functionsconcerns0the types1of gates used. It is sometimes11S1Fdesirable to implement a Boolean function solely with NAND gates or solely S2withNOR gates. Although this mayit has1 not be1the minimum-gate10 implementation,Figure 11.4Sum-of-ProductsImplementationof Table 11.30 the0D0advantage of regularity, which can simplify the manufacturing process. Consider0again Equation (11.3):11D10D2F = A B1C + A BC +1 ABCF = B(A + C)nnn2n đầu vào dữ liệun đầu vào chọn1 đầu ra dữ liệuMỗi tổ hợp đầu vào chọn (S) xác định đầu vàodữ liệu nào (D) sẽ được nối với đầu ra (F)D3Because the complement of the complement of a value is just the original value,output signal F. To select one of the four possible inputs, a 2-bit selection code is2017F = B(A + C) = (AB + (BC) needed, and this is implemented as two select lines labeled S1 and S2.Kiếntrúc máytính multiplexer is defined by the truth table in Table 11.7.73 ThisAnexample4-to-1is a simplified form of a truth table. Instead of showing all possible combinations ofinput variables, it shows the output as data from line D0, D1, D2, or D3. Figure 11.13F = (AB)•(BC)shows an implementation using AND, OR, and NOT gates. S1 and S2 are connectedwhich has three NAND forms, as illustrated in Figure 11.11.to the AND gates in such a way that, for any combination of S1 and S2, three of theAND gates will output 0. The fourth AND gate will output the value of the selectedline, which is either 0 or 1. Thus, three of the inputs to the OR gate are always 0,Multiplexersand the output of the OR gate will equal the value of the selected input gate. UsingThe multiplexer connectsmultiple inputs to a single output.thisAt regularany time,one of theit is easy to construct multiplexers of size 8-to-1, 16-to-1,NKK-HUSTorganization,so on. representationinputs is selected to be passed to the output. A general blockanddiagramMultiplexersareinputused in digital circuits to control signal and data routing. Anis shown in Figure 11.12. This represents a 4-to-1 multiplexer. Thereare fourtheprovideloading ofthe program counter (PC). The value to be loaded into thelines, labeled D0, D1, D2, and D3. One of these lines is exampleselectedistotheprogram counter may come from one of several different sources:Applying DeMorgan’s theorem,2017Kiến trúc máy tínhNKK-HUSTBộ chọn kênh 4 đầu vàoS2Bộ giải mã (Decoder)nS1D0nD14-to-1MUXD2FD0nD3N đầu vào, 2N đầu raVới một tổ hợp của N đầu vào, chỉ có một đầu ra tích cực(khác với các đầu ra còn lại)Ví dụ: Bộ giải mã 2 ra 42:4DecoderD1S2S1Figure 11.12 4-to-1 MultiplexerRepresentationĐầuvàochọn Đầura2017S2S1F00110101D0D1D2D3A1A0FD2A111100100Y3Y2Y1Y0Y20010Y10100Y2A10011Figure 11.13 Multiplexer ImplementationF = D0 • S2 • S1+ D1• S2 • S1+ D2 • S2 • S1+ D3• S2 • S1Nguyễn Kim Khánh DCE-HUSTA0Y3D3Kiến trúc máy tính74752017A00101Y30001Y01000Y1Y0Kiến trúc máy tính7619Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTThực hiện bộ giải mã 3 ra 8ABộ cộng38311.3 / COMBINATIONAL CIRCUITS000 D0nBBộ cộng bán phần 1-bit (Half-adder)001 D1nC010 D2nCộng hai bit tạo ra bit tổng và bit nhớ raBộ cộng toàn phần 1-bit (Full-adder)n011 D3nCộng 3 bitCho phép xây dựng bộ cộng N-bit100 D4101 D5110 D6111 D7Figure 11.15 Decoder with 3 Inputs and 23 = 8 OutputsKiến trúc máy tính2017772017Kiến trúc máy tính78A0A7NKK-HUST256 ϫ 8RAM256 ϫ 8RAM256 ϫ 8RAMBộ cộng bán phần 1-bit2-to-4DecoderEnableEnableNKK-HUST256 ϫ 8RAMEnableBộ cộng toàn phần 1-bitEnableAA8A90 Figure 11.16011Address Decoding+0+1+0+101110CoutAB1-bitHalfAdder2017Đầu raABSCoutS = AÅ B0000C out = AB011110110Cin11.3 / COMBINATIONAL CIRCUITSSĐầu vàoĐầu raABSCout0000000110010100011010110010101011100111111792017S = ABC + ABC + ABC + ABCCout = AB + AC + BC387ABCCinKiến trúc máy tínhNguyễn Kim Khánh DCE-HUST1-bitFullAdderCoutSĐầu vàoBABCABCSSumABCABACCCarryoutBCKiến trúc máy tínhFigure 11.20 Implementation of an Adder80Thus we have the necessary logic to implement a multiple-bit adder such asshown in Figure 11.21. Note that because the output from each adder depends onthe 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 amountof gate delay, and this gate delay accumulates. For larger adders, the accumulateddelay can become unacceptably high.If the carry values could be determined without having to ripple through allthe previous stages, then each single-bit adder could function independently, anddelay would not accumulate. This can be achieved with an approach known as carrylookahead. Let us look again at the 4-bit adder to explain this approach.20This truth table could easily be implemented in digital logic. However, we are notinterested in performingA addition on just a single pair of bits. Rather, we wish toadd two n-bit numbers. CThis can be done by putting togetherCarrya set of adders so thatthe carry from one adder is provided as input to the next. A 4-bit adder is depictedin Figure 11.19.BFor a multiple-bit adderto work, each of the single-bit adders must have threeCinputs, including the carry from the next-lower-order adder. The revised truth table11.20Implementationof an Adderappears in Table 11.9b. FigureThe twooutputscan be expressed:Bài giảng Kiến trúc máy tínhCA-20172Sum = A BC + ABC + ABC + ABCNKK-HUSTNKK-HUSTThus we havethe necessarylogic+toBCimplement a multiple-bit adder such asCarry= AB + ACshown in Figure 11.21. Note that because the output from each adder depends onFigure 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 amountof gate delay,A andBthis gate delaylarger adders,A2 accumulates.B2AForBA0 theB0accumulated3311delay can become unacceptably high.If the carry values could be determined without having to ripple through allOverflowthe previousstages,Cthen eachsingle-bitaddercould CfunctionC independently,and0C3C2CinC1Cininin0signaldelay would not accumulate. This can be achieved with an approach known as carrylookahead. 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 toany stage of theSadder without referenceto previouscarry values. WehaveSSSBộ cộng 4-bit và bộ cộng 32-bit3212.5. Mạch dãyMạch dãy là mạch logic trong đó đầu ra phụthuộc giá trị đầu vào ở thời điểm hiện tại vàđầu vào ở thời điểm quá khứnLà mạch có nhớ, được thực hiện bằng phầntử nhớ (Latch, Flip-Flop) và có thể kết hợpvới các cổng logicn0Figure 11.19 4-Bit Adder392A31 B31 A24 B24 A23 B23CHAPTER 11 / DIGITAL LOGICC238-bitadderCoutS31Figure 11.21S23ClockA15 B15C158-bitadderKS24A16 B16S16A8 B8C78-bitadderS15A 7 B7A0 B08-bitCinQ adderS8S7S0Construction of a 32-Bit Adder Using 8-Bit AddersJQ2017Kiến trúc máy tính812017Kiến trúc máy tính82Figure 11.26 J–K Flip-FlopNKK-HUSTcausing the output to be 1; if only the K input is asserted, the result is a reset function,causing the output to be 0. When both J and K are 1, the function performed isreferred to as the toggle function: the output is reversed. Thus, if Q is 1 and 1 is appliedto J and K, then Q becomes 0. The reader should verify that the implementation ofFigure 11.26 produces this characteristic function.NKK-HUSTCác Flip-Flop cơ bảnS-R Latch và các Flip-Flop11.4 / SEQUENTIAL CIRCUITSNameGraphical SymbolSRTruth TableSRQnϩ1RQ00110101Qn01–JQJKQnϩ1KQ00110101Qn01QnDQDQnϩ10101Ck11.4 / SEQUENTIAL CIRCUITSRDCkKiến trúc máy tínhFigure 11.27 Basic Flip-FlopsNguyễn Kim Khánh DCE-HUSTFigure 11.24Figure 11.22 The S–R Latch Implementedwith NOR GatesQ83Q392Clocked S–R Flip-FlopS-R Flip-FlopQCHAPTER 11 / DIGITAL LOGICFirst, let us show that the circuit is bistable. Assume that both S and R are 0Figure 11.24 Clocked S–R Flip-Flopand that Q is 0. The inputs to the lower NOR gate are Q = 0 and S = 0. Thus, theClockoutput Q = 1 means that the inputs to the upper NOR gate are Q = 1 and R = 0,QKwhich has the output Q = 0. Thus, the state of the circuit is internally consistentQand remains stable as long as S = R = 0. A similar line of reasoning shows that theQstate Q = 1, Q = 0 is also stable for R = S = 0.DThus, this circuit can function as a 1-bit memory. We can view the output Q asClockFigure11.25 D Flip-FlopClockthe “value” of the bit. Theinputs S and R serve to write the values 1 and 0, respectively, into memory. To see this, consider the state Q = 0, Q = 1, S = 0, R = 0.This device is referred to as a clocked S–R flip-flop. Note that theSuppose that S changes to the value 1. Now the inputs to the lower NOR gatearrangement.areQR beand S inputs are passedto the NOR gates only during the clock pulse.S = 1, Q = 0. After some time delay ^t, the output of the lower NOR gatewillJQDQ = 0 (see Figure 11.23). So, at this point in time, the inputs to the upper NORDgateFLIP-FLOP One problem with S–R flip-flop is that the condition R = 1, S = 111.25Flip-Flopbecome R = 0,FigureQ = 0.AfterDanothergate delay of ^t the output Q becomes 1. mustThis be avoided. One way to do this is to allow just a single input. The D flip-flopis again a stable state. The inputs to the lower gate are now S = 1, Q = 1, whichFigure 11.26 J–K Flip-Flopaccomplishes this.Figure 11.25 shows a gate implementation of the D flip-flop. Bymaintainthe output= 0. Aslong as Sto=as1 aandR = 0,theflip-flop.outputs willarrangement.ThisQdeviceis referredclockedS–RNoteremainthat theusing an inverter, the nonclock inputs to the two AND gates are guaranteed to beQR= and1, QS=inputs0. Furthermore,if theS returns0, theoutputsunchanged.are passed toNOR togatesonlyduringwilltheremainclock pulse.the opposite of each other.The R output performs the opposite function. When R goes to 1, it forcescausing theDoutputto be1; if only theK inputtoisasasserted,theresult isbecausea reset function,flip-flopis sometimesreferredthe dataflip-flopit is, inDFLIP-FLOP One problem with S–R flip-flop is that the condition R = 1, S = The1Q = 0, Q = 1 regardless of the previous state of Q and Q. Again, a time delayofcausingthe outputtobitbeof0.data.WhenbothJ andK are1, the functionperformedeffect, storagefor oneTheoutputof theD flip-flopis always equalto the ismust be avoided. One way to do this is to allow just a single input. The D flip-flop2^t occurs before the final state is established (Figure 11.23).referredto asvaluethe togglefunction:outputis reversed.Thus, andif Q is1 and 1 isappliedmostByrecentappliedto the theinput.Hence,it remembersproducesthelastaccomplishes 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, calledaand K, then Q becomes 0. The reader should verify that the implementation oftoJusing an inverter, the nonclock inputs to the two AND gates are guaranteedto beIt is also referred to as the delay flip-flop, because it delays a 0 or 1 applied toinput.characteristictable,whichshowsthenextstateorstatesofasequentialcircuitasFigure11.26producesthischaracteristicfunction.2017Kiếnitstrúctheopposite of each other.inputmáyfor atínhsingle clock pulse. We can capture the logic of the D flip-flop in the84a function of current states and inputs. In the case of the S–R latch, the state canThe D flip-flop is sometimes referred to as the data flip-flop because followingit 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 theObserve that the inputs S = 1, R = 1 are not allowed, because these would proDQn ؉ 1most recent value applied to the input. Hence, it remembers and produces the lastduce an inconsistent output (both Q and Q equal 0). The table can be expressedinput. It is also referred to as the delay flip-flop, because it delays a 0 or 1 applied toNameGraphical SymbolTruth Table00more compactly, as in Table 11.10b. An illustration of the behavior of the S–R latchits input for a single clock pulse. We can capture the logic of the D flip-flop in the11is shown in Table 11.10c.following truth table:SQSRQnϩ1CLOCKED S–R FLIP-FLOP The output of the S–R latch changes, after a briefJ–K FLIP-FLOP Another useful flip-flop is the J–K flip-flop. Like the S–R flip-flop,D input.Qn ؉This1time delay, in response to a change in theis referred to as asynchronous00it has two inputs. However, in this case all possible combinationsofQinputvalues arenoperation. More typically, events in the digitalcomputerare synchronized to a clockCk00S–R0and Figure 11.2710flip-flop,pulse, so that changes occur only when a1clock 1pulse occurs. Figure 11.24 showsvalid.this Figure 11.26 shows a gate implementation of the J–Kshows its characteristic table (along with those for the1 S–R 0and D1flip-flops). Note–11Q same as for thethat the first three combinationsRare theS–R flip-flop. With no inputJ–K FLIP-FLOP Another useful flip-flop is the J–K flip-flop. Like the S–R flip-flop,asserted, the output is stable. If only the J input is asserted, the result is a set function,it has two inputs. However, in this case all possible combinations of input values arevalid. Figure 11.26 shows a gate implementation of the J–K flip-flop, and Figure 11.27JQJKQnϩ1D Flip FlopQ2017ClockSQClockSS-R LatchCk391391QQSJ–K11.4 / SEQUENTIAL CIRCUITSRQS–R389QJ-K Flip-Flop21PARALLEL REGISTERS A parallel register consists of a set of 1-bit memories thatcan be read or written simultaneously. It is used to store data. The registers that wehave discussed throughout this book are parallel registers.The 8-bit register of Figure 11.28 illustrates the operation of a parallel registerusing D flip-flops. A control signal, labeled load, controls writing into the registerfrom signal lines, D11 through D18. These lines might be the output of multiplexers,so that data from a variety of sources can be loaded into the register.Bài giảng Kiến trúc máy tínhSHIFT REGISTER A shift register accepts and/or transfers information serially.NKK-HUSTConsider, for example, Figure 11.29, which shows a 5-bit shift register constructedfrom clocked D flip-flops. Data are input only to the leftmost flip-flop. With eachclock pulse, data are shifted to the right one position, and the rightmost bit istransferred out.Shift registers can be used to interface to serial I/O devices. In addition, theycan be used within the ALU to perform logical shift and rotate functions. In thisNKK-HUSTThanh ghi 8-bit song songThanh ghi dịch 5-bit39311.4 / SEQUENTIAL CIRCUITSData linesD18D17D16D15D14D13D12D11Serial inDQClkDQDClk394ClockLoadQDClkQDClkQDClkCA-20172QDClkQDClkQDClkDQClkDQClkDQClkDQSerial outClkQClkCHAPTER 11 / DIGITAL LOGIClatter capacity, they need to be equipped with parallel read/write circuitry as wellas serial.D08D07D06D05CountersD04D03D02ClockFigure 11.29 5-Bit Shift RegisterD01Output linesAnotherusefulcategoryof sequential circuit is the counter. A counter is a registerFigure 11.288-BitParallelRegister2017NKK-HUSTwhose value is easily incremented by 1 modulo the capacity of the register; that is,after the maximum value is achieved the next increment sets the counter value to 0.RegistersThus,a register made up of n flip-flops can count up to 2n - 1. An example of acounterin the CPUis thecounter.As an exampleof theuseprogramof flip-flops,let us first examine one of the essential elecan thebe designatedasynchronousor synchronous,dependingmentsCountersof the CPU:register. Asasweknow, a registeris a digital circuitused onwithinthewayinwhichtheyoperate.Asynchronousaretypesrelativelyslow becausethe CPU to store one or more bits of data. countersTwo basicof registersare comthe output of one flip-flop triggers a change in the status of the next flip-flop. In amonly used: parallel registers andregisters.Kiếnshifttrúc máytínhsynchronous counter, all of the flip-flops change state at the same time. Because thelattertype isREGISTERSmuch faster, Ait isthe kindused inconsistsCPUs. However,it isusefulto beginthatPARALLELparallelregisterof a set of1-bitmemoriesthea descriptionof an asynchronouscan discussionbe read orwithwrittensimultaneously.It is used tocounter.store data. The registers that we85have discussedthroughoutthis bookcounterare parallelRIPPLECOUNTERAn asynchronousis alsoregisters.referred to as a ripple counter,Thethe8-bitregisterFigureto11.28illustratesoperationparallelbecausechangethatofoccursincrementthe thecounterstartsofataoneend registerandusing D flip-flops.A thecontrollabeled11.30load,showscontrolswriting into the ofregister“ripples”through toothersignal,end. Figurean implementationafrom countersignal lines,D18.Thesewithlinesa mightthe outputof multiplexers,4-bitusingD11J–Kthroughflip-flops,togethertimingbediagramthat illustratesitsso that datafroma varietyof issourcescaninbethatloadedintotheregister.behavior.Thetimingdiagramidealizedit doesnotshowthe propagationdelay that occurs as the signals move down the series of flip-flops. The output ofSHIFT REGISTER A shift register accepts and/or transfers information serially.the leftmost flip-flop (Q0) is the least significant bit. The design could clearly beConsider, for example, Figure 11.29, which shows a 5-bit shift register constructedextended to an arbitrary number of bits by cascading more flip-flops.2017Kiến trúc máy tính86NKK-HUSTBộ đếm 4-bitfrom clocked D flip-flops. Data are input only to the leftmost flip-flop. With eachHighpulse, data are shifted to the right one position, and the rightmost bit isclocktransferred out.JQ be used toJ interfaceQJ I/OQ devices. In Jaddition,QShift registerscanto serialtheycan be used within the ALU to perform logical shift and rotate functions. In thisCkClockSerial inKDCkQQClkQKDQ0ClkCkQDQQClk1KDCkQQClkDQ2QKClkQ Serial outHết chương 2Q3(a) Sequential circuitClockQClock0Figure 11.29 5-Bit Shift RegisterQ1Q2Q3(b) Timing diagramFigure 11.30 Ripple Counter2017Kiến trúc máy tínhNguyễn Kim Khánh DCE-HUST872017Kiến trúc máy tính8822Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTKiến trúc máy tínhNội dung học phầnChương 1. Giới thiệu chungChương 2. Cơ bản về logic sốChương 3. Hệ thống máy tínhChương 4. Số học máy tínhChương 5. Kiến trúc tập lệnhChương 6. Bộ xử lýChương 7. Bộ nhớ máy tínhChương 8. Hệ thống vào-raChương 9. Các kiến trúc song songChương 3HỆ THỐNG MÁY TÍNHNguyễn Kim KhánhTrường Đại học Bách khoa Hà Nội2017Kiến trúc máy tính89NKK-HUST2017Kiến trúc máy tínhNKK-HUSTNội dung của chương 33.1. Các thành phần cơ bản của máy tínhn3.1. Các thành phần cơ bản của máy tính3.2. Hoạt động cơ bản của máy tính3.3. Bus máy tínhCPUBộ nhớ chínhBộ xử lý trung tâm (CentralProcessing Unit – CPU)nnBus hệ thốngnNguyễn Kim Khánh DCE-HUST912017Trao đổi thông tin giữa máy tínhvới bên ngoàiBus hệ thống (System bus)nKiến trúc máy tínhChứa các chương trình đangthực hiệnHệ thống vào-ra (Input/Output)nnĐiều khiển hoạt động của máytính và xử lý dữ liệuBộ nhớ chính (Main Memory)nHệ thống vào-ra201790Kết nối và vận chuyển thông tinKiến trúc máy tính9223Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUST1. Bộ xử lý trung tâm (CPU)nChức năng:nnnnđiều khiển hoạt động của máy tínhxử lý dữ liệuĐơn vịsố học và logicCPU hoạt động theo chương trình nằm trongbộ nhớ chính.Đơn vị điều khiểnnĐơn vịđiều khiểnNguyên tắc hoạt động cơ bản:nnCác thành phần cơ bản của CPUnBushệ thốngnĐơn vị số học và logicnnnLà thành phần nhanh nhất trong hệ thốngTập thanh ghiKiến trúc máy tính93NKK-HUST2017nRegister File (RF)Gồm các thanh ghi chứa các thôngtin phục vụ cho hoạt động của CPUKiến trúc máy tính94NKK-HUST2. Bộ nhớ máy tínhnnnnThao tác ghi (Write)Thao tác đọc (Read)nCác thành phần chính:nnnBộ nhớ chính (Main memory)Chức năng: nhớ chương trình và dữ liệu (dưới dạngnhị phân)Các thao tác cơ bản với bộ nhớ:nnnnBộ nhớ chính (Main memory)Bộ nhớ đệm (Cache memory)Thiết bị lưu trữ (Storage Devices)nCPUBộ nhớđệmBộ nhớchínhCácthiết bịlưu trữn2017Arithmetic and Logic Unit (ALU)Thực hiện các phép toán số học vàphép toán logicTập thanh ghin2017Control Unit (CU)Điều khiển hoạt động của máy tínhtheo chương trình đã định sẵnKiến trúc máy tínhNguyễn Kim Khánh DCE-HUST952017Tồn tại trên mọi máy tínhChứa các lệnh và dữ liệu củachương trình đang được thực hiệnSử dụng bộ nhớ bán dẫnTổ chức thành các ngăn nhớđược đánh địa chỉ (thường đánhđịa chỉ cho từng byte nhớ)Nội dung của ngăn nhớ có thểthay đổi, song địa chỉ vật lý củangăn nhớ luôn cố địnhCPU muốn đọc/ghi ngăn nhớ cầnphải biết địa chỉ ngăn nhớ đóKiến trúc máy tínhNội dungĐịa chỉ0100110100...00000101010100...00011010111100...00100000111000...00110111010000...01001011001000...01010010 100000...01101110111100...0111...0110001011...11100010000111...11119624Bài giảng Kiến trúc máy tínhCA-20172NKK-HUSTNKK-HUSTBộ nhớ đệm (Cache memory)nnnnnnThiết bị lưu trữ (Storage Devices)nBộ nhớ có tốc độ nhanh được đặt đệm giữaCPU và bộ nhớ chính nhằm tăng tốc độ CPUtruy cập bộ nhớDung lượng nhỏ hơn bộ nhớ chínhSử dụng bộ nhớ bán dẫn tốc độ nhanhCache thường được chia thành một số mức (L1,L2, L3)Cache thường được tích hợp trên cùng chip bộxử lýCache có thể có hoặc không2017Kiến trúc máy tínhnChức năng: Trao đổithông tin giữa máy tínhvới thế giới bên ngoàiCác thao tác cơ bản:nnCác loại thiết bị lưu trữBộ nhớ từ: ổ đĩa cứng HDDBộ nhớ bán dẫn: ổ thể rắn SSD, ổ nhớ flash, thẻ nhớBộ nhớ quang: CD, DVDnnn972017Kiến trúc máy tính98Các thiết bị vào-ranBushệthốngThiếtbịvào-ranMô-đunvào-ranThiếtbịvào-raVào dữ liệu (Input)Ra dữ liệu (Output)nCác thiết bị vào-ra(IO devices)Các mô-đun vào-ra(IO modules)nnMô-đunvào-raKiến trúc máy tínhNguyễn Kim Khánh DCE-HUSTCòn được gọi là thiết bị ngoại vi (Peripherals)Chức năng: chuyển đổi dữ liệu giữa bên trongvà bên ngoài máy tínhCác loại thiết bị vào-ra:nCác thành phần chính:n2017Tốc độ chậmNKK-HUSTnnnn3. Hệ thống vào-rannLưu giữ tài nguyên phần mềm của máy tínhĐược kết nối với hệ thống dưới dạng các thiết bị vào-raDung lượng lớnnNKK-HUSTnCòn được gọi là bộ nhớ ngoàiChức năng và đặc điểmThiếtbịvào-ran992017Thiết bị vào (Input Devices)Thiết bị ra (Output Devices)Thiết bị lưu trữ (Stotage Devices)Thiết bị truyền thông (Communication Devives)Kiến trúc máy tính10025