Collegeofcomputerscience,SWPUComputerScience数字逻辑Digitallogic主讲颜俊华第九讲比较器、加法器数字逻辑CollegeofComputerScience,SWPU比较器(comparator)比较器:比较两个二进制数值并指示其是否相等的电路。等值比较器:检验数值是否相等。数值比较器:比较数值的大小(,=,)。数字逻辑CollegeofComputerScience,SWPU一位数值比较器设A>B时L1=1;A<B时L2=1;A=B时L3=1。得1位数值比较器的真值表。ABL1(AB)L2(AB)L3(A=B)00011011001010100001数字逻辑CollegeofComputerScience,SWPU一位数值比较器BABAABBALBALBAL321AB11≥1L1(AB)L3(A=B)L2(AB)&&逻辑表达式逻辑图数字逻辑CollegeofComputerScience,SWPU多位比较器可由多个二进制一位比较器构成。比较规则:首先是对最高位进行比较,如果最高位不等,电路就可直接输出结果。只有在最高位相等时,才对次高位进行比较,依次逐位进行比较,直到比较出最后的结果。数字逻辑CollegeofComputerScience,SWPU四位比较器比较输入输出A3B3A2B2A1B1A0B0ABABA=BA3B3A3B3A3=B3A3=B3A3=B3A3=B3A3=B3A3=B3A3=B3A3=B3A3=B3××A2B2A2B2A2=B2A2=B2A2=B2A2=B2A2=B2A2=B2A2=B2××××A1B1A1B1A1=B1A1=B1A1=B1A1=B1A1=B1××××××A0B0A0B0A0=B0A0=B0A0=B0100010100010100010100010001010001数字逻辑CollegeofComputerScience,SWPU数字逻辑CollegeofComputerScience,SWPU四位比较器数码比较器——74851.逻辑功能四位并行数码比较器逻辑符号A3B2A2B1A1B0A0CA<BCA=BCA>BPA<BPA=BPA>BB3COMP数字逻辑CollegeofComputerScience,SWPU表:四位比较器功能表数字逻辑CollegeofComputerScience,SWPU比较器的扩展例:试比较两个七位二进制整数的大小。数字逻辑CollegeofComputerScience,SWPU加法器半加器(halfadder)和全加器(fulladder)0000010110011110ABSCO半加器真值表相加的和:S=A’·B+A·B’=AB向高位的进位:CO=A·B0000000101010010111010001101101101011111CIXYSCO全加器真值表数字逻辑CollegeofComputerScience,SWPU加法器SCOXYCIS=XYCI半加器(halfadder)和全加器(fulladder)00100111CIXY0001111001COCO=X·Y+CI·X’·Y+CI·X·Y’=X·Y+(XY)·CI0000000101010010111010001101101101011111CIXYSCO全加器真值表数字逻辑CollegeofComputerScience,SWPU串行进位加法器缺点:运算速度慢,有较大的传输延迟tADD=tXYCout+(n-2)*tCinCout+tCinSXYCICOSXYCICOSXYCICOSXYCICOSC1C2C3C4C0S0S1S2S3X0Y0X1Y1X2Y2X3Y3=0——提高速度:并行加法器数字逻辑CollegeofComputerScience,SWPU并行进位加法器一位全加器:S=XYCiCi+1=X·Y+(XY)·CiCi+1=(Xi·Yi)+(XiYi)·Ci=Gi+Pi·Ci进位产生信号进位传递信号0000000101010010111010001101101101011111CiXYSCi+1全加器真值表先行进位法:第i位的进位输入信号可以由该位以前的各位状态决定。数字逻辑CollegeofComputerScience,SWPU并行进位加法器先行进位法:第i位的进位输入信号可以由该位以前的各位状态决定。C0=0Ci+1=Gi+Pi·CiC0=0C1=G0+P0·C0C2=G1+P1·C1=G1+P1·(G0+P0·C0)=G1+P1·G0+P1·P0·C0……Cn=Gn+Pn·Cn展开为“与-或”式:三级延迟