Arithmetic Logic Unit Digital Computer Design
Arithmetic Circuits Arithmetic circuits are the central building blocks of computers. Computers and digital logic perform many arithmetic functions: addition, subtraction, comparisons, shifts, multiplication and division 2
-Bit Adders Half Adder Full Adder A B A B C out + C out + C in S S A B C out S = A B C out = AB S C in A B C out S S = A B C in C out = AB + AC in + BC in 3
Multibit Adders - Carry Propagate Adders (CPAs) An N-bit adder sums two N-bit inputs A and B, and a carry in C in to produce an N-bit result S and a carry out C out. A N B N C out + S N C in Multibit adder is commonly called a carry propagate adder (CPA) because the carry out of one bit propagates into the next bit. 4
CPAs: - Ripple-Carry Adder Chain together N full adders. The C out of one stage acts as the C in of the next stage A 3 B 3 A 3 B 3 A B A B C out + C + 3 C 29 C + C + C in S 3 S 3 S S The ripple-carry adder is slow when N is large. For an 32-bit adder, S 3 depends on C 3, which depends on C 29, which depends on C 28, and so forth all the way back to C in. 5
CPAs: - Ripple-Carry Adder The fundamental reason that large ripple-carry adders are slow is that the carry signals must propagate through every bit in the adder. A 3 B 3 A 3 B 3 A B A B C out + C + 3 C 29 C + C + C in S 3 S 3 S S tripple = Nt FA where t FA is the delay of a -bit full adder 6
CPAs: 2- Carry-Lookahead Adder (CLA) Generate (G i ): Column i will generate a carry out if A i and B i are both. C i- A i A i- G i = A i B i Propagate (P i ): Column i will propagate a carry in B i B i- C i S i S i- (C i- ) to the carry out if A i or B i is. P i = A i + B i Carry out (C i ): The carry out of column i is: C i = A i B i + (A i +B i )C i- = G i + P i C i- 7
CPAs: 2- Carry-Lookahead Adder (CLA) A 3 A 2 A A C in B 3 B 2 B B C 3: S 3 S 2 S S Propagate and generate signals for 4-bit blocks (P 3: and G 3: ): P 3: = P 3 P 2 P P G 3: = G 3 + P 3 (G 2 + P 2 (G + P G ) C 3: = G 3: + P 3: C in 8
CPAs: 2- Carry-Lookahead Adder (CLA) B 3:28 A 3:28 B 27:24 A 27:24 B 7:4 A 7:4 B 3: A 3: C out 4-bit CLA Block C 27 4-bit CLA Block C 23 C 7 4-bit CLA Block C 3 4-bit CLA Block C in S 3:28 S 27:24 S 7:4 S 3: All G i:j and P i:j are computed in parallel C out B 3 A 3 + S 3 G 3: C 2 B 2 A 2 + S 2 C B A + S C B + S A C in G 3 P 3 G 2 P 2 G P G independently C in propagates through each k-bit propagate/ generate logic (meanwhile computing sums) C out C in P 3: P 3 P 2 P P 32-bit CLA with 4-bit Blocks 9
CPAs: 2- Carry-Lookahead Adder (CLA) For N-bit CLA with k-bit blocks, the delay is: t CLA = t pg + t pg_block + (N/k )t AND_OR + kt FA t pg : generate all P i, G i t pg_block : generate all P i:j, G i:j t AND_OR t pg_block t pg
CPAs: Ripple-Carry Adder vs CLA Assume that each two-input gate delay is ps and that a full adder delay is 3 ps. The CLA has t pg = ps, t pg_block =6x ps = 6 ps, and t AND_OR = 2x ps = 2 ps. 32-bit ripple-carry adder Delay is 32x3 ps = 9.6 ns. 32-bit carry-lookahead adder with 4-bit blocks Delay is ps+ 6 ps + (32/4 )x2 ps + (4x3 ps) = 3.3 ns. CLA is almost three times faster than the ripple-carry adder.
Subtracter Subtraction is almost as easy: flip the sign of the second number, then add. Symbol Implementation A N - Y B N N N A B Flipping the sign of a two s complement number is done by inverting the bits and adding. + Y N N N 2
Comparator: Equality A comparator determines whether two binary numbers are equal or if one is greater or less than the other. Symbol Implementation A 3 B 3 A 4 = B 4 A 2 B 2 A Equal Equal B A B 3
Comparator: Less Than Compute A B and looking at the sign (most significant bit) of the result. If the result is negative (i.e., the sign bit is ), then A is less than B. Otherwise A is greater than or equal to B. A B N N - N [N-] A < B Sign bit This comparator, however, functions incorrectly upon overflow. 4
ALU: Arithmetic Logic Unit An Arithmetic/Logical Unit (ALU ) combines a variety of mathematical and logical operations into a single unit. The ALU forms the heart of most computer systems. ALUControl : Function Add Subtract AND OR The ALU receives a 2-bit control signal ALUControl that specifies which function to perform. 5
ALU Implementation ALUControl : Function Add Subtract AND OR 6
ALU Implementation ALUControl : Function Add Subtract AND OR Example: Perform A OR B ALUControl : = Mux selects output of OR gate as Result Result = A OR B 7
ALU Implementation ALUControl : Function Add Subtract AND OR Example: Perform A + B ALUControl : = C in to adder = 2 nd input to adder is B Mux selects Sum as Result Result = A + B 8
ALU with Status Flags Flag N Z C V Description Result is Negative Result is Zero Adder produces Carry out Adder overflowed Some ALUs produce extra outputs, called flags, that indicate information about the ALU output. 9
ALU with Status Flags 2
ALU with Status Flags: Negative N = if: Result is negative So, N is connected to most significant bit of Result 2
ALU with Status Flags: Zero Z = if: all of the bits of Result are 22
ALU with Status Flags: Carry C = if: C out of Adder is AND ALU is adding or subtracting (ALUControl is or ) 23
ALU with Status Flags: overflow V = if: The addition of 2 samesigned numbers produces a result with the opposite sign. (the result is too big to fit in the available digits.) 24
ALU with Status Flags: overflow V = if: ALU is performing addition or subtraction (ALUControl = ) 25
ALU with Status Flags: overflow V = if: ALU is performing addition or subtraction (ALUControl = ) AND A and Sum have opposite signs 26
ALU with Status Flags: overflow V = if: ALU is performing addition or subtraction (ALUControl = ) AND A and Sum have opposite signs AND A and B have same signs upon addition (ALUControl = ) OR A and B have different signs upon subtraction (ALUControl = ) 27
Shifters/Rotators Shifters and rotators move bits and multiply or divide by powers of 2. As the name implies, a shifter shifts a binary number left or right by a specified number of positions. Logical shifter: shifts value to left or right and fills empty spaces with s Ex: >> 2 = Ex: << 2 = 28
Shifters/Rotators Arithmetic shifter: right shift, fills empty spaces with the old most significant bit (msb) Ex: >>> 2 = Ex: <<< 2 = Rotator: rotates bits in a circle, such that bits shifted off one end are shifted into the other end Ex: ROR 2 = Ex: ROL 2 = 29
Example: Logical Shift Right Implementation An N-bit shifter can be built from N N: multiplexers. The input is shifted by to N bits, depending on the value of the log 2 N-bit select lines. A 3 A 2 A A shamt : 2 S : S : Y 3 Y 2 shamt : A Y 3: >> 3: 2 4 4 S : Y Depending on the value of the 2-bit shift amount shamt :, the output Y receives the input A shifted by to 3 bits. (Ground) S : Y 3
Further Reading You can read Chapter 5 of your book From Section 5. to 5.2.5 3