700 likes | 731 Views
Explore key concepts in binary arithmetic and logic operations including adders, comparators, shifters, multipliers, and dividers. Understand floating-point number representations and learn about different methods such as 1's and 2's complement. Dive into single-bit addition using half and full adders. Discover various adder designs including carry-ripple and carry-propagate adders, along with the concepts of propagate and generate. Delve into carry-lookahead and carry-select adders for efficient computation. Learn about comparators, detectors, and equality/magnitude comparison for binary numbers, and understand the differences between signed and unsigned representations. Master different types of shifts, logical, arithmetic, and rotation operations, to manipulate binary data effectively.
E N D
Introduction to Computer Organization and Architecture Lecture 10 By Juthawut Chantharamalee http://dusithost.dusit.ac.th/~juthawut_cha/home.htm
Outline • Adders • Comparators • Shifters • Multipliers • Dividers • Floating Point Numbers Introduction to Computer Organization and Architecture
Binary Representations of Numbers • To find negative numbers • Sign and magnitude: msb = ‘1’ • 1’s complement: complement each bit to change sign • 2’s complement: 2n – positive number Introduction to Computer Organization and Architecture
Single-Bit Addition Half Adder Full Adder Introduction to Computer Organization and Architecture 4
Single-Bit Addition Half Adder Full Adder Introduction to Computer Organization and Architecture
Carry-Ripple Adder • Simplest design: cascade full adders • Critical path goes from Cin to Cout • Design full adder to have fast carry delay Introduction to Computer Organization and Architecture
Carry Propagate Adders • N-bit adder called CPA • Each sum bit depends on all previous carries • How do we compute all these carries quickly? Introduction to Computer Organization and Architecture
Propagate and Generate - Define • An n-bit adder is just a combinational circuit • si = a XOR b XOR c = aibi’ci’ + ai’bici’ + ai’bi’ci + aibici • ci+1 = MAJ(a,b,c) = aibi + aici + bici • Want to write si in “sum of products” form • ci+1 = gi + pici, where gi = aibi, pi = ai + bi • if gi is true, then ci+1 is true, thus carry is generated • if pi is true, and if ci is true, ci is propagated • Note that the pi equation can also be written as pi = ai XOR bi since gi = 1 when ai = bi = 1 (i.e. generate occurs, so propagate is a “don’t care”) Introduction to Computer Organization and Architecture
Propagate and Generate - Blocks • In the general case, for any j with i<j, j+1<k • ck+1 = Gik + Pikci • Gik = Gj+1,k + Pj+1,k Gij • Pik = PijPj+1,k • Gik equation in words: • A carry is generated out of the block consisting of bits i through k inclusive if • it is generated in the high-order part of the block (j+1, k) or • it is generated in the low-order (i,j) part of the block and then propagated through the high part Introduction to Computer Organization and Architecture
Propagate and Generate-Lookahead Recursively apply to eliminate carry terms ci+1 = gi + pigi-1 + pipi-1gi-2 + … + pipi-1…p1g0 + pipi-1…p1p0c0 This is a carry-lookahead adder Note large fan-in of OR gate and last AND gate Too big! Build p’s and g’s in steps c1 = g0 + p0c0 c2 = G01 + P01c0 Where: G01 = g1 + p1g0,P01 = p1p0 Introduction to Computer Organization and Architecture 10
PG Logic Introduction to Computer Organization and Architecture
Carry-Ripple Revisited • G03 = G3 + P3 G02 Introduction to Computer Organization and Architecture
Carry-Skip Adder • Carry-ripple is slow through all N stages • Carry-skip allows carry to skip over groups of n bits • Decision based on n-bit propagate signal Introduction to Computer Organization and Architecture
Carry-Lookahead Adder • Carry-lookahead adder computes G0i for many bits in parallel. • Uses higher-valency cells with more than two inputs. Introduction to Computer Organization and Architecture
Carry-Select Adder • Trick for critical paths dependent on late input X • Precompute two possible outputs for X = 0, 1 • Select proper output when X arrives • Carry-select adder precomputes n-bit sums • For both possible carries into n-bit group Introduction to Computer Organization and Architecture
Comparators • 0’s detector: A = 00…000 • 1’s detector: A = 11…111 • Equality comparator: A = B • Magnitude comparator: A < B Introduction to Computer Organization and Architecture
1’s & 0’s Detectors • 1’s detector: N-input AND gate • 0’s detector: NOTs + 1’s detector (N-input NOR) Introduction to Computer Organization and Architecture
Equality Comparator • Check if each bit is equal (XNOR, aka equality gate) • 1’s detect on bitwise equality Introduction to Computer Organization and Architecture
Magnitude Comparator • Compute B-A and look at sign • B-A = B + ~A + 1 • For unsigned numbers, carry out is sign bit Introduction to Computer Organization and Architecture
Signed vs. Unsigned • For signed numbers, comparison is harder • C: carry out • Z: zero (all bits of A-B are 0) • N: negative (MSB of result) • V: overflow (inputs had different signs, output sign B) Introduction to Computer Organization and Architecture
Shifters • Logical Shift: • Shifts number left or right and fills with 0’s • 1011 LSR 1 = ____ 1011 LSL1 = ____ • Arithmetic Shift: • Shifts number left or right. Rt shift sign extends • 1011 ASR1 = ____ 1011 ASL1 = ____ • Rotate: • Shifts number left or right and fills with lost bits • 1011 ROR1 = ____ 1011 ROL1 = ____ Introduction to Computer Organization and Architecture
Shifters • Logical Shift: • Shifts number left or right and fills with 0’s • 1011 LSR 1 = 0101 1011 LSL1 = 0110 • Arithmetic Shift: • Shifts number left or right. Rt shift sign extends • 1011 ASR1 = 1101 1011 ASL1 = 0110 • Rotate: • Shifts number left or right and fills with lost bits • 1011 ROR1 = 1101 1011 ROL1 = 0111 Introduction to Computer Organization and Architecture
Funnel Shifter • A funnel shifter can do all six types of shifts • Selects N-bit field Y from 2N-bit input • Shift by k bits (0 k < N) Introduction to Computer Organization and Architecture
Funnel Shifter Operation • Computing N-k requires an adder Introduction to Computer Organization and Architecture
Funnel Shifter Operation • Computing N-k requires an adder Introduction to Computer Organization and Architecture
Funnel Shifter Operation • Computing N-k requires an adder Introduction to Computer Organization and Architecture
Funnel Shifter Operation • Computing N-k requires an adder Introduction to Computer Organization and Architecture
Funnel Shifter Operation • Computing N-k requires an adder Introduction to Computer Organization and Architecture
Simplified Funnel Shifter • Optimize down to 2N-1 bit input Introduction to Computer Organization and Architecture
Simplified Funnel Shifter • Optimize down to 2N-1 bit input Introduction to Computer Organization and Architecture
Simplified Funnel Shifter • Optimize down to 2N-1 bit input Introduction to Computer Organization and Architecture
Simplified Funnel Shifter • Optimize down to 2N-1 bit input Introduction to Computer Organization and Architecture
Simplified Funnel Shifter • Optimize down to 2N-1 bit input Introduction to Computer Organization and Architecture
Funnel Shifter Design 1 • N N-input multiplexers • Use 1-of-N hot select signals for shift amount Introduction to Computer Organization and Architecture
Funnel Shifter Design 2 • Log N stages of 2-input muxes • No select decoding needed Introduction to Computer Organization and Architecture
Multi-input Adders • Suppose we want to add k N-bit words • Ex: 0001 + 0111 + 1101 + 0010 = _____ Introduction to Computer Organization and Architecture
Multi-input Adders • Suppose we want to add k N-bit words • Ex: 0001 + 0111 + 1101 + 0010 = 10111 Introduction to Computer Organization and Architecture
Multi-input Adders • Suppose we want to add k N-bit words • Ex: 0001 + 0111 + 1101 + 0010 = 10111 • Straightforward solution: k-1 N-input CPAs • Large and slow Introduction to Computer Organization and Architecture
Carry Save Addition • A full adder sums 3 inputs and produces 2 outputs • Carry output has twice weight of sum output • N full adders in parallel are called carry save adder • Produce N sums and N carry outs Introduction to Computer Organization and Architecture
CSA Application • Use k-2 stages of CSAs • Keep result in carry-save redundant form • Final CPA computes actual result Introduction to Computer Organization and Architecture
CSA Application • Use k-2 stages of CSAs • Keep result in carry-save redundant form • Final CPA computes actual result Introduction to Computer Organization and Architecture
CSA Application • Use k-2 stages of CSAs • Keep result in carry-save redundant form • Final CPA computes actual result Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: Introduction to Computer Organization and Architecture
Multiplication • Example: • M x N-bit multiplication • Produce N M-bit partial products • Sum these to produce M+N-bit product Introduction to Computer Organization and Architecture
General Form • Multiplicand: Y = (yM-1, yM-2, …, y1, y0) • Multiplier: X = (xN-1, xN-2, …, x1, x0) • Product: Introduction to Computer Organization and Architecture