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
- Adders and Subtractors: full adders, ripple-carry and carry-lookahead adders, and subtraction as .
- Fixed-Point Arithmetic and Overflow: two's-complement ranges and when a sum overflows.
Core concepts
The ALU as a block
| Port | Width | Meaning |
|---|---|---|
| A, B | bits each | Operands |
| F (function select) | bits | Chooses the operation |
| 1 | Carry in (used for subtraction and multi-word arithmetic) | |
| Result | bits | Output |
| Flags | Z, N, C, V | Zero, 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 . Shifts are performed by a separate shifter (often a barrel shifter) in front of or beside the ALU.
Condition flags
| Flag | Set when | Meaning |
|---|---|---|
| Z | every result bit is 0 | Result is zero |
| N | result bit is 1 | Result is negative if read as signed |
| C | carry out of bit is 1 | Unsigned overflow in addition; in subtraction by , means a borrow ( unsigned) |
| V | carry into bit carry out of bit | Signed (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
| Shift | Vacated bits filled with | Arithmetic meaning |
|---|---|---|
| Logical left | 0 | Multiply by 2 (signed or unsigned, if no overflow) |
| Logical right | 0 | Unsigned divide by 2, rounding down |
| Arithmetic right | Copy of the sign bit | Signed divide by 2, rounding toward |
| Rotate | Bits shifted out at the other end | No arithmetic meaning |
Multiplication
Unsigned shift-and-add. For -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 steps the -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 through as : subtract at its start and add after its end. A run reaching the sign bit contributes , so it needs only the opening subtraction. Each step looks at the pair , the current low multiplier bit and the bit shifted out last:
| Action, then arithmetic shift right of A, Q, | ||
|---|---|---|
| 0 | 0 | none (inside a run of 0s) |
| 1 | 1 | none (inside a run of 1s) |
| 1 | 0 | (start of a run of 1s) |
| 0 | 1 | (end of a run of 1s) |
Equivalently, bit of the multiplier is recoded as , with .
Bit-pair recoding (radix-4 Booth). Grouping the Booth digits two at a time, the pair at positions and (for even ) has weight and value , read from the three bits :
| 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 | |
|---|---|---|---|---|---|---|---|---|
| Multiple of | 0 | 0 |
Every digit is in , and is just shifted left, so an -bit multiplier ( even) needs at most partial products instead of . The alternating multiplier that is Booth's worst case becomes cheap.
How it works


Algorithms and pseudocode
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 productRESTORING-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 -bit numbers, overflow occurs exactly when both operands have the same sign and the result has the other sign, which is the same as , where is the carry into the sign bit and the carry out of it.
Why Booth works. With , the value of a two's-complement multiplier satisfies
because the sum telescopes. So adding for every gives , and the sign bit needs no special step.
Operation counts. Booth performs one add or subtract per position where . An alternating multiplier can require 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 , shifting right arithmetically by gives .
Worked examples
Example 1: flags of 4-bit additions
| Operation (4 bits) | Result | Z | N | C | V | Reading |
|---|---|---|---|---|---|---|
| 0111 + 0001 | 1000 | 0 | 1 | 0 | 1 | overflows the signed range to 7 |
| 1111 + 0001 | 0000 | 1 | 0 | 1 | 0 | Unsigned overflows; signed is correct |
| 1000 + 1000 | 0000 | 1 | 0 | 1 | 1 | overflows both ways |
| 0011 + 0100 | 0111 | 0 | 0 | 0 | 0 | , fine |
Example 2: subtraction and the borrow
is computed as with carry out 0. Unsigned: signals a borrow, since . Signed: , correct, . Compare instructions use exactly this subtraction and keep only the flags.
Example 3: Booth trace (Figure 2)
, , , 4-bit registers.
| Step | Action | A after action | A, Q, after shift | |
|---|---|---|---|---|
| Start | 0000, 1101, 0 | |||
| 1 | 10 | 1001 | 1100, 1110, 1 | |
| 2 | 01 | 0011 | 0001, 1111, 0 | |
| 3 | 10 | 1010 | 1101, 0111, 1 | |
| 4 | 11 | none | 1101 | 1110, 1011, 1 |
Product A:Q . The recoded multiplier is from bit 3 down to bit 0: .
Example 4: counting Booth operations
For 8-bit multipliers:
- : every adjacent pair differs, so 8 operations (4 subtractions, 4 additions). Shift-and-add would need 4 additions; Booth is worse here.
- : 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.
- : only bit 0 starts a run, so 1 operation (a subtraction): the product is .
Example 5: shifts of a negative number
(4 bits). Arithmetic right shift: . Logical right shift: , which is for the unsigned reading 11. Left shift: with a lost sign bit, so overflows the 4-bit range.
Example 6: restoring division (Related material)
Related material. Unsigned with 4-bit registers: the quotient is and the remainder . 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 in the next step instead.
Example 7: bit-pair recoding
For (4 bits, ): the low pair reads , digit ; the high pair reads , digit with weight 4. So , and from 2 partial products instead of the 4 steps of Figure 2.
For the 8-bit , every pair reads , giving digits 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 steps; other hardware implementations may be combinational or pipelined.
- C reports unsigned overflow, V signed overflow; .
- In subtraction by two's complement, C = 0 means a borrow.
- Arithmetic right shift rounds toward ; 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 -bit A register fails for one multiplicand, , because is not representable in 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.
- " starts as the sign bit." It starts as 0.
GATE examination perspective
- FLAGS. Add in binary, record and , then read Z, N, C and V.
- BOOTH TRACE. Keep columns for A, Q and ; act on , then shift arithmetically.
- BOOTH RECODING. Digit ; count non-zero digits for the operation count.
- BIT-PAIR RECODING. Read overlapping triples for even ; digit , at most partial products, sign-extending for odd .
- SHIFTS. Arithmetic right shift copies the sign; logical inserts 0.
- FUNCTION SELECT. Bits .
- ADDER DELAY. Rebuild from the gate model given; the derivations are in the Digital Logic note.
Summary
Sources
- 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).
- 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).
- W. Stallings, Computer Organization and Architecture, 10th ed., Pearson: Sections 10.1 (The Arithmetic and Logic Unit) and 10.3 (Integer Arithmetic).