Loading lessons...
Multiplication Algorithms: Shift-and-Add, Booth's Algorithm & the Array Multiplier
Multiplication Algorithms: Shift-and-Add, Booth's Algorithm & the Array Multiplier
The basic computer multiplied with a program (lesson 32). A processor's arithmetic unit does it in hardware, in one of three ways: a sequential shift-and-add circuit for signed-magnitude numbers, Booth's algorithm for 2's complement numbers, or a fast combinational array multiplier. This lesson works each one through with step-by-step tables.
1. Shift-and-Add Multiplication (Signed Magnitude)
By hand, we multiply by looking at each bit of the multiplier: write the multiplicand (shifted) when the bit is 1, write 0s when it is 0, then add all the rows. The hardware makes two changes:
- Instead of storing all the shifted rows, it keeps a running partial product and adds the multiplicand to it when the bit is 1.
- Instead of shifting the multiplicand left, it shifts the partial product right, which has the same effect.
The sign of the product is computed separately: Ps = As oplus Bs (signs equal → positive).
Hardware for shift-and-add multiplication
The multiplier is in Q, the multiplicand in B; A (with its carry E) collects the partial product, and SC counts the bits. Algorithm:
- As ← Qs oplus Bs, Qs ← Qs oplus Bs; A ← 0, E ← 0, SC ← n (number of magnitude bits).
- If Qn (the low bit of Q) is 1: EA ← A + B.
- Shift right EAQ: shr \ EAQ; SC ← SC - 1.
- If SC ≠ 0 repeat from step 2. The product is in AQ (2n bits).
Multiplicand B = 10111 (23), multiplier Q = 10011 (19). Trace E, A, Q and SC.
| Step | E | A | Q | SC |
|---|---|---|---|---|
| Initial | 0 | 00000 | 10011 | 5 |
| Qn = 1: add B | 0 | 10111 | 10011 | |
| shr EAQ | 0 | 01011 | 11001 | 4 |
| Qn = 1: add B | 1 | 00010 | 11001 | |
| shr EAQ | 0 | 10001 | 01100 | 3 |
| Qn = 0: shr EAQ | 0 | 01000 | 10110 | 2 |
| Qn = 0: shr EAQ | 0 | 00100 | 01011 | 1 |
| Qn = 1: add B | 0 | 11011 | 01011 | |
| shr EAQ | 0 | 01101 | 10101 | 0 |
The product AQ = 01101 10101 = 437.
2. Booth's Algorithm (Signed 2's Complement)
Booth's algorithm multiplies 2's complement numbers directly, without converting signs. It is based on the fact that a string of 1s in the multiplier needs no additions, only shifts: a string of 1s from bit k down to bit m has the value
For example, multiplier 001110 (14) has 1s from k = 3 to m = 1: 14 = 24 - 21 = 16 - 2. So M × 14 = M × 24 - M × 21: one subtraction and one addition instead of three additions.
Scanning the multiplier from right to left, with an extra bit Qn+1 (initially 0) appended to its right:
| Qn | Qn+1 | Meaning | Action |
|---|---|---|---|
| 1 | 0 | first 1 of a string of 1s | subtract the multiplicand: AC ← AC + overline{BR} + 1 |
| 0 | 1 | first 0 after a string of 1s | add the multiplicand: AC ← AC + BR |
| 0 | 0 | inside a string of 0s | nothing |
| 1 | 1 | inside a string of 1s | nothing |
After the (possible) add or subtract, arithmetic shift right AC, QR and Qn+1 together (the sign of AC is kept), and decrement SC. Repeat n times.
Flowchart of Booth's algorithm
BR = 10111 (−9), so overline{BR} + 1 = 01001. QR = 10011 (−13). Trace AC, QR, Qn+1 and SC.
| Qn Qn+1 | Operation | AC | QR | Qn+1 | SC |
|---|---|---|---|---|---|
| initial | 00000 | 10011 | 0 | 5 | |
| 10 | subtract BR | 01001 | |||
| ashr | 00100 | 11001 | 1 | 4 | |
| 11 | ashr | 00010 | 01100 | 1 | 3 |
| 01 | add BR | 11001 | |||
| ashr | 11100 | 10110 | 0 | 2 | |
| 00 | ashr | 11110 | 01011 | 0 | 1 |
| 10 | subtract BR | 00111 | |||
| ashr | 00011 | 10101 | 1 | 0 |
BR = 0101, overline{BR} + 1 = 1011, QR = 1101 (−3).
- Qn Qn+1 = 10: AC = 0000 + 1011 = 1011; ashr: AC = 1101, QR = 1110, Qn+1 = 1.
- 01: AC = 1101 + 0101 = 0010; ashr: AC = 0001, QR = 0111, Qn+1 = 0.
- 10: AC = 0001 + 1011 = 1100; ashr: AC = 1110, QR = 0011, Qn+1 = 1.
- 11: ashr only: AC = 1111, QR = 0001, Qn+1 = 1.
Booth's algorithm needs fewer additions when the multiplier has long strings of 1s (or 0s). Its worst case is an alternating pattern such as 0101 0101, where every step is an add or a subtract.
The sequential Booth multiplier below performs one Qn Qn+1 step per clock, and the testbench reproduces Example 2:
// Booth's multiplication algorithm, one step per clock, for 5-bit
// 2's complement numbers: AC and QR form the product, Qn+1 is the extra bit
module booth #(parameter N = 5) (
input clk,
input start,
input [N-1:0] br, // multiplicand
input [N-1:0] qr_in, // multiplier
output reg [N-1:0] ac,
output reg [N-1:0] qr,
output reg qn1,
output reg [3:0] sc
);
reg [N-1:0] sum;
always @(*)
case ({qr[0], qn1})
2'b10: sum = ac + ~br + 1'b1; // AC <- AC + BR' + 1 (subtract)
2'b01: sum = ac + br; // AC <- AC + BR (add)
default: sum = ac; // 00 or 11: no arithmetic
endcase
always @(posedge clk)
if (start) begin
ac <= 0;
qr <= qr_in;
qn1 <= 1'b0;
sc <= N;
end else if (sc != 0) begin
// ashr (AC & QR & Qn+1): the sign of AC is kept
{ac, qr, qn1} <= {sum[N-1], sum, qr};
sc <= sc - 1'b1;
end
endmodule
module tb;
reg clk = 0, start = 1;
reg [4:0] br = 5'b10111; // -9
reg [4:0] qr = 5'b10011; // -13
wire [4:0] ac, q;
wire qn1;
wire [3:0] sc;
booth u (clk, start, br, qr, ac, q, qn1, sc);
always #5 clk = ~clk;
initial begin
@(posedge clk);
#1 start = 0;
$display("initial AC=%b QR=%b Qn+1=%b SC=%0d", ac, q, qn1, sc);
while (sc != 0) begin
$write("Qn Qn+1 = %b%b ", q[0], qn1);
@(posedge clk);
#1 $display("AC=%b QR=%b Qn+1=%b SC=%0d", ac, q, qn1, sc);
end
$display("product = %b = %0d", {ac, q}, $signed({ac, q}));
$finish;
end
endmoduleThe register contents after each step match Mano's table row by row, and the 10-bit product is +117:
initial AC=00000 QR=10011 Qn+1=0 SC=5
Qn Qn+1 = 10 AC=00100 QR=11001 Qn+1=1 SC=4
Qn Qn+1 = 11 AC=00010 QR=01100 Qn+1=1 SC=3
Qn Qn+1 = 01 AC=11100 QR=10110 Qn+1=0 SC=2
Qn Qn+1 = 00 AC=11110 QR=01011 Qn+1=0 SC=1
Qn Qn+1 = 10 AC=00011 QR=10101 Qn+1=1 SC=0
product = 0001110101 = 1173. The Array Multiplier
The sequential methods need n clock cycles. An array multiplier forms the product in one pass through combinational logic: AND gates make every partial-product bit ai bj, and adders sum them.
For 2-bit numbers A = a1 a0 and B = b1 b0:
So c0 = a0 b0, and two half adders add the middle and left columns:
2-bit by 2-bit array multiplier
For a multiplier of j bits and a multiplicand of k bits, the array needs j × k AND gates and (j - 1) adders of k bits each, producing a (j + k)-bit product.
How many AND gates and adders does a 4-bit by 3-bit array multiplier need (multiplicand 4 bits, multiplier 3 bits)? How many bits are in the product?
- AND gates: j × k = 3 × 4 = 12.
- Adders: j - 1 = 2 adders of 4 bits.
- Product: j + k = 7 bits.
The gate-level 2 × 2 multiplier is checked for all 16 input pairs (a "!" would mark a wrong product):
// 2-bit by 2-bit array multiplier: four AND gates and two half adders
module half_adder (
input x,
input y,
output s,
output c
);
assign s = x ^ y;
assign c = x & y;
endmodule
module array_mult_2x2 (
input [1:0] a,
input [1:0] b,
output [3:0] c
);
wire p00 = a[0] & b[0];
wire p10 = a[1] & b[0];
wire p01 = a[0] & b[1];
wire p11 = a[1] & b[1];
wire k1;
assign c[0] = p00;
half_adder ha1 (p10, p01, c[1], k1);
half_adder ha2 (p11, k1, c[2], c[3]);
endmodule
module tb;
reg [1:0] a, b;
wire [3:0] c;
integer i, j;
array_mult_2x2 u (a, b, c);
initial begin
$display("B1B0 x A1A0: 00 01 10 11");
for (i = 0; i < 4; i = i + 1) begin
b = i;
$write(" %b ", b);
for (j = 0; j < 4; j = j + 1) begin
a = j;
#1 $write(" %b", c);
if (c != a * b) $write("!");
else $write(" ");
end
$display("");
end
end
endmoduleEvery entry equals the product of its row and column, for example 11 × 11 = 1001 (3 × 3 = 9):
B1B0 x A1A0: 00 01 10 11
00 0000 0000 0000 0000
01 0000 0001 0010 0011
10 0000 0010 0100 0110
11 0000 0011 0110 1001| Method | Numbers | Time | Hardware |
|---|---|---|---|
| Shift-and-add | signed magnitude | n clocks | one adder, registers |
| Booth | 2's complement | n clocks (fewer additions for strings) | one adder/subtractor, registers |
| Array | unsigned (or with sign correction) | one combinational delay | n2 AND gates, n - 1 adders |
Key points to remember
- Shift-and-add: if Qn = 1 add B to A; shr EAQ; n times; sign As oplus Bs.
- Booth: 10 subtract, 01 add, 00 and 11 nothing; then ashr AC QR Qn+1.
- Booth uses 2k+1 - 2m for a string of 1s from bit k to bit m.
- Array: j × k AND gates, j - 1 k-bit adders, j + k bit product.
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Explain the hardware and flowchart for multiplication of signed-magnitude numbers. Multiply 23 × 19 showing each step. (10 Marks)
- Q2. State Booth's algorithm with a flowchart. Multiply (−9) × (−13) using it. (10 Marks)
- Write: the 10/01/00/11 rules, BR'+1, and the full AC, QR, Qn+1, SC table.
- Q3. Why does Booth's algorithm work? Explain with a string of 1s. (5 Marks)
- Q4. Draw a 2-bit by 2-bit array multiplier. How many gates and adders does a 4 × 3 array multiplier need? (5 Marks)
- Q5. Multiply (+5) × (−3) using Booth's algorithm with 4-bit registers. (5 Marks)