Introduction

The arithmetic logic unit (ALU) is the combinational block of the datapath that performs integer arithmetic (add, subtract, compare), bitwise logic (AND, OR, XOR, NOT) and shifts on two operands, under the control of a function-select input, and reports the outcome in condition flags. Multiplication and division are built on top of the ALU's adder as sequences of add or subtract steps and shifts.

GATE asks you to set the flags for a given operation, to tell carry from overflow, to evaluate arithmetic against logical shifts, to trace Booth's algorithm step by step, and to count the additions and subtractions a multiplier needs. Gate-level adder design, including ripple-carry and carry-lookahead delay, belongs to Adders and Subtractors; overflow rules for two's complement are in Fixed-Point Arithmetic and Overflow.

Prerequisites

Core concepts

The ALU as a block

PortWidthMeaning
A, Bnn bits eachOperands
F (function select)⌈lg⁡(number of functions)⌉\lceil \lg(\text{number of functions}) \rceil bitsChooses the operation
cinc_{in}1Carry in (used for subtraction and multi-word arithmetic)
Resultnn bitsOutput
FlagsZ, N, C, VZero, Negative (sign), Carry, Overflow

A common construction is a bit slice: each bit position has an AND gate, an OR gate and a full adder, and a multiplexer driven by F picks one of them. Subtraction inverts B (an XOR with a control line) and sets cin=1c_{in} = 1. Shifts are performed by a separate shifter (often a barrel shifter) in front of or beside the ALU.

Condition flags

FlagSet whenMeaning
Zevery result bit is 0Result is zero
Nresult bit n−1n-1 is 1Result is negative if read as signed
Ccarry out of bit n−1n-1 is 1Unsigned overflow in addition; in subtraction A−BA - B by A+B‾+1A + \overline{B} + 1, C=0C = 0 means a borrow (A<BA < B unsigned)
Vcarry into bit n−1n-1 ≠\ne carry out of bit n−1n-1Signed (two's-complement) overflow

C and V are independent: an addition can set either, both or neither. The hardware computes both; the program decides whether the operands were signed or unsigned.

Shifts

ShiftVacated bits filled withArithmetic meaning
Logical left0Multiply by 2 (signed or unsigned, if no overflow)
Logical right0Unsigned divide by 2, rounding down
Arithmetic rightCopy of the sign bitSigned divide by 2, rounding toward −∞-\infty
RotateBits shifted out at the other endNo arithmetic meaning

Multiplication

Unsigned shift-and-add. For nn-bit operands, examine the multiplier bits from the least significant: if the bit is 1, add the multiplicand into the upper half of the partial product; then shift the partial product right. After nn steps the 2n2n-bit product is complete. The number of additions equals the number of 1s in the multiplier.

Booth's algorithm (signed, two's complement). Booth's algorithm treats an interior run of 1s from bit ii through jj as 2j+1−2i2^{j+1}-2^i: subtract at its start and add after its end. A run reaching the sign bit contributes −2i-2^i, so it needs only the opening subtraction. Each step looks at the pair (Q0,Q−1)(Q_0, Q_{-1}), the current low multiplier bit and the bit shifted out last:

Q0Q_0Q−1Q_{-1}Action, then arithmetic shift right of A, Q, Q−1Q_{-1}
00none (inside a run of 0s)
11none (inside a run of 1s)
10A←A−MA \leftarrow A - M (start of a run of 1s)
01A←A+MA \leftarrow A + M (end of a run of 1s)

Equivalently, bit ii of the multiplier is recoded as Qi−1−Qi∈{−1,0,+1}Q_{i-1} - Q_i \in \{-1, 0, +1\}, with Q−1=0Q_{-1} = 0.

Bit-pair recoding (radix-4 Booth). Grouping the Booth digits two at a time, the pair at positions i+1i + 1 and ii (for even ii) has weight 2i2^i and value −2Qi+1+Qi+Qi−1-2Q_{i+1} + Q_i + Q_{i-1}, read from the three bits Qi+1QiQi−1Q_{i+1} Q_i Q_{i-1}:

Qi+1QiQi−1Q_{i+1} Q_i Q_{i-1}000001010011100101110111
Multiple of MM0+1+1+1+1+2+2−2-2−1-1−1-10

Every digit is in {−2,−1,0,+1,+2}\{-2, -1, 0, +1, +2\}, and ±2M\pm 2M is just MM shifted left, so an nn-bit multiplier (nn even) needs at most n/2n/2 partial products instead of nn. The alternating multiplier that is Booth's worst case becomes cheap.

How it works

ALU block with operands, function select, carry in, result and flags
Figure 1. An nn-bit ALU: operands A and B, a function-select input F and a carry in enter; the result and the flags Z, N, C and V leave; inside, a multiplexer driven by F picks the AND, OR or adder output of each bit slice.
Booth multiplication trace of 7 times minus 3 in 4 bits
Figure 2. Booth trace of 7×(−3)7 \times (-3) with 4-bit registers: four steps of subtract, add, subtract and no operation, each followed by an arithmetic right shift, end with A:Q = 1110 1011, which is −21-21.

Algorithms and pseudocode

Text
BOOTH(M, Q, n)                    // M multiplicand, Q multiplier, n-bit two's complement
  A <- 0;  Q_1 <- 0               // Q_1 is the extra bit to the right of Q
  repeat n times
      if (Q[0], Q_1) = (1, 0)  then A <- A - M
      if (Q[0], Q_1) = (0, 1)  then A <- A + M
      arithmetic shift right the combined register A : Q : Q_1 by one bit
  return A : Q                    // 2n-bit product
Text
RESTORING-DIVIDE(N, D, n)         // unsigned N / D, n-bit quotient
  A <- 0;  Q <- N
  repeat n times
      shift A : Q left by one bit
      A <- A - D
      if A < 0 then  A <- A + D;  Q[0] <- 0     // restore
      else           Q[0] <- 1
  return (quotient Q, remainder A)

Mathematical explanation

Overflow. For two's-complement addition of nn-bit numbers, overflow occurs exactly when both operands have the same sign and the result has the other sign, which is the same as V=cn⊕cn−1V = c_{n} \oplus c_{n-1}, where cn−1c_{n-1} is the carry into the sign bit and cnc_n the carry out of it.

Why Booth works. With Q−1=0Q_{-1} = 0, the value of a two's-complement multiplier satisfies

Q=−Qn−12n−1+∑i=0n−2Qi2i=∑i=0n−1(Qi−1−Qi) 2i,Q = -Q_{n-1}2^{n-1} + \sum_{i=0}^{n-2} Q_i 2^i = \sum_{i=0}^{n-1} (Q_{i-1} - Q_i)\,2^{i},

because the sum telescopes. So adding (Qi−1−Qi) M 2i(Q_{i-1} - Q_i)\,M\,2^i for every ii gives M×QM \times Q, and the sign bit needs no special step.

Operation counts. Booth performs one add or subtract per position where Qi≠Qi−1Q_i\ne Q_{i-1}. An alternating multiplier can require nn operations. Each interior run of ones needs two operations; a run reaching the sign bit needs only its opening subtraction, so a run costs at most two.

Arithmetic right shift. For a two's-complement value xx, shifting right arithmetically by kk gives ⌊x/2k⌋\lfloor x / 2^k \rfloor.

Worked examples

Example 1: flags of 4-bit additions

Operation (4 bits)ResultZNCVReading
0111 + 0001100001017+1=87 + 1 = 8 overflows the signed range −8-8 to 7
1111 + 000100001010Unsigned 15+115 + 1 overflows; signed −1+1=0-1 + 1 = 0 is correct
1000 + 100000001011−8+(−8)-8 + (-8) overflows both ways
0011 + 0100011100003+4=73 + 4 = 7, fine

Example 2: subtraction and the borrow

0011−01010011 - 0101 is computed as 0011+1010+1=11100011 + 1010 + 1 = 1110 with carry out 0. Unsigned: C=0C = 0 signals a borrow, since 3<53 < 5. Signed: 1110=−21110 = -2, correct, V=0V = 0. Compare instructions use exactly this subtraction and keep only the flags.

Example 3: Booth trace (Figure 2)

M=7=0111M = 7 = 0111, Q=−3=1101Q = -3 = 1101, −M=1001-M = 1001, 4-bit registers.

StepQ0Q−1Q_0 Q_{-1}ActionA after actionA, Q, Q−1Q_{-1} after shift
Start0000, 1101, 0
110A−MA - M10011100, 1110, 1
201A+MA + M00110001, 1111, 0
310A−MA - M10101101, 0111, 1
411none11011110, 1011, 1

Product A:Q =1110 1011=−21= 1110\,1011 = -21. The recoded multiplier is (0,−1,+1,−1)(0, -1, +1, -1) from bit 3 down to bit 0: −4+2−1=−3-4 + 2 - 1 = -3.

Example 4: counting Booth operations

For 8-bit multipliers:

  • 0101 01010101\,0101: every adjacent pair differs, so 8 operations (4 subtractions, 4 additions). Shift-and-add would need 4 additions; Booth is worse here.
  • 0011 11000011\,1100: a single run of 1s from bit 2 to bit 5, so 2 operations (subtract at bit 2, add at bit 6), against 4 additions for shift-and-add.
  • 1111 1111=−11111\,1111 = -1: only bit 0 starts a run, so 1 operation (a subtraction): the product is −M-M.

Example 5: shifts of a negative number

x=1011=−5x = 1011 = -5 (4 bits). Arithmetic right shift: 1101=−3=⌊−5/2⌋1101 = -3 = \lfloor -5/2 \rfloor. Logical right shift: 0101=50101 = 5, which is ⌊11/2⌋\lfloor 11/2 \rfloor for the unsigned reading 11. Left shift: 01100110 with a lost sign bit, so −10-10 overflows the 4-bit range.

Related material. Unsigned 7÷37 \div 3 with 4-bit registers: the quotient is 00100010 and the remainder 00010001. Each of the 4 steps subtracts; the three steps that produce a 0 quotient bit must restore. Non-restoring division removes the restore additions by adding DD in the next step instead.

Example 7: bit-pair recoding

For Q=−3=1101Q = -3 = 1101 (4 bits, Q−1=0Q_{-1} = 0): the low pair reads Q1Q0Q−1=010Q_1 Q_0 Q_{-1} = 010, digit +1+1; the high pair reads Q3Q2Q1=110Q_3 Q_2 Q_1 = 110, digit −1-1 with weight 4. So Q=−1×4+1=−3Q = -1 \times 4 + 1 = -3, and 7×(−3)=−28+7=−217 \times (-3) = -28 + 7 = -21 from 2 partial products instead of the 4 steps of Figure 2.

For the 8-bit 0101 0101=850101\,0101 = 85, every pair reads 010010, giving digits +1,+1,+1,+1+1, +1, +1, +1 at weights 64, 16, 4, 1: 4 additions, against 8 operations for plain Booth (Example 4).

Important properties and observations

  • The ALU is combinational. The iterative multiplication and division algorithms described here are sequential, driven by the control unit over nn steps; other hardware implementations may be combinational or pipelined.
  • C reports unsigned overflow, V signed overflow; V=cn⊕cn−1V = c_n \oplus c_{n-1}.
  • In subtraction by two's complement, C = 0 means a borrow.
  • Arithmetic right shift rounds toward −∞-\infty; it is not the same as C integer division for negative odd numbers.
  • Booth handles signed operands directly and saves work on runs of 1s, but alternating bits make it worst.
  • Booth needs an arithmetic, not a logical, shift so that negative partial products keep their sign.
  • Booth with an nn-bit A register fails for one multiplicand, M=−2n−1M = -2^{n-1}, because −M-M is not representable in nn bits; widening A (and M) by one bit removes the problem.
  • Common misconceptions.
    • "Carry out means overflow." Only for unsigned numbers.
    • "Booth always uses fewer additions." It does not for alternating multipliers.
    • "Q−1Q_{-1} starts as the sign bit." It starts as 0.

GATE examination perspective

  • FLAGS. Add in binary, record cn−1c_{n-1} and cnc_n, then read Z, N, C and V.
  • BOOTH TRACE. Keep columns for A, Q and Q−1Q_{-1}; act on (Q0,Q−1)(Q_0, Q_{-1}), then shift arithmetically.
  • BOOTH RECODING. Digit i=Qi−1−Qii = Q_{i-1} - Q_i; count non-zero digits for the operation count.
  • BIT-PAIR RECODING. Read overlapping triples Qi+1QiQi−1Q_{i+1} Q_i Q_{i-1} for even ii; digit =−2Qi+1+Qi+Qi−1= -2Q_{i+1} + Q_i + Q_{i-1}, at most ⌈n/2⌉\lceil n/2\rceil partial products, sign-extending for odd nn.
  • SHIFTS. Arithmetic right shift copies the sign; logical inserts 0.
  • FUNCTION SELECT. Bits =⌈lg⁡(functions)⌉= \lceil \lg(\text{functions}) \rceil.
  • ADDER DELAY. Rebuild from the gate model given; the derivations are in the Digital Logic note.

Summary

Sources

  1. C. Hamacher, Z. Vranesic, S. Zaky, Computer Organization, 5th ed., McGraw-Hill, 2002, Chapter 6 (Arithmetic), Sections 6.2 (Design of Fast Adders), 6.3 (Multiplication of Positive Numbers), 6.4 (Signed-Operand Multiplication, including 6.4.1 Booth Algorithm), 6.5 (Fast Multiplication, including 6.5.1 Bit-Pair Recoding) and 6.6 (Integer Division).
  2. D. A. Patterson, J. L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 5th ed. (MIPS edition), Morgan Kaufmann, 2013: Section 3.3 (Multiplication); Appendix B, Section B.5 (Constructing a Basic Arithmetic Logic Unit).
  3. W. Stallings, Computer Organization and Architecture, 10th ed., Pearson: Sections 10.1 (The Arithmetic and Logic Unit) and 10.3 (Integer Arithmetic).

Next steps