Lesson 38 +40 XP

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:

  1. Instead of storing all the shifted rows, it keeps a running partial product and adds the multiplicand to it when the bit is 1.
  2. 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 multiplicationHardware 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:

  1. As ← Qs oplus Bs, Qs ← Qs oplus Bs; A ← 0, E ← 0, SC ← n (number of magnitude bits).
  2. If Qn (the low bit of Q) is 1: EA ← A + B.
  3. Shift right EAQ: shr \ EAQ; SC ← SC - 1.
  4. If SC ≠ 0 repeat from step 2. The product is in AQ (2n bits).
SolvedExample 1 · 23 × 19 with 5-bit magnitudes (Mano)

Multiplicand B = 10111 (23), multiplier Q = 10011 (19). Trace E, A, Q and SC.

StepEAQSC
Initial000000100115
Qn = 1: add B01011110011
shr EAQ001011110014
Qn = 1: add B10001011001
shr EAQ010001011003
Qn = 0: shr EAQ001000101102
Qn = 0: shr EAQ000100010111
Qn = 1: add B01101101011
shr EAQ001101101010

The product AQ = 01101 10101 = 437.

Answer23 × 19 = 437 = 0110110101

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

2k+1 - 2m

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:

QnQn+1MeaningAction
10first 1 of a string of 1ssubtract the multiplicand: AC ← AC + overline{BR} + 1
01first 0 after a string of 1sadd the multiplicand: AC ← AC + BR
00inside a string of 0snothing
11inside a string of 1snothing

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 algorithmFlowchart of Booth's algorithm

SolvedExample 2 · (−9) × (−13) with Booth's algorithm (Mano)

BR = 10111 (−9), so overline{BR} + 1 = 01001. QR = 10011 (−13). Trace AC, QR, Qn+1 and SC.

Qn Qn+1OperationACQRQn+1SC
initial000001001105
10subtract BR01001
ashr001001100114
11ashr000100110013
01add BR11001
ashr111001011002
00ashr111100101101
10subtract BR00111
ashr000111010110
AnswerAC QR = 00011 10101 = +117
SolvedExample 3 · (+5) × (−3) with 4 bits

BR = 0101, overline{BR} + 1 = 1011, QR = 1101 (−3).

  1. Qn Qn+1 = 10: AC = 0000 + 1011 = 1011; ashr: AC = 1101, QR = 1110, Qn+1 = 1.
  2. 01: AC = 1101 + 0101 = 0010; ashr: AC = 0001, QR = 0111, Qn+1 = 0.
  3. 10: AC = 0001 + 1011 = 1100; ashr: AC = 1110, QR = 0011, Qn+1 = 1.
  4. 11: ashr only: AC = 1111, QR = 0001, Qn+1 = 1.
AnswerAC QR = 1111 0001 = −15
💡 Tip

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:

VERILOG
// 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
endmodule

The register contents after each step match Mano's table row by row, and the 10-bit product is +117:

OUTPUT
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 = 117

3. 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:

begin{array}{rrrr} & & a1 & a0 \\ × & & b1 & b0 \\ hline & & a1 b0 & a0 b0 \\ & a1 b1 & a0 b1 & \\ hline c3 & c2 & c1 & c0 end{array}

So c0 = a0 b0, and two half adders add the middle and left columns:

2-bit by 2-bit array multiplier2-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.

SolvedExample 4 · Sizing an array multiplier

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?

  1. AND gates: j × k = 3 × 4 = 12.
  2. Adders: j - 1 = 2 adders of 4 bits.
  3. Product: j + k = 7 bits.
Answer12 AND gates, two 4-bit adders, 7-bit product

The gate-level 2 × 2 multiplier is checked for all 16 input pairs (a "!" would mark a wrong product):

VERILOG
// 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
endmodule

Every entry equals the product of its row and column, for example 11 × 11 = 1001 (3 × 3 = 9):

OUTPUT
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
MethodNumbersTimeHardware
Shift-and-addsigned magnituden clocksone adder, registers
Booth2's complementn clocks (fewer additions for strings)one adder/subtractor, registers
Arrayunsigned (or with sign correction)one combinational delayn2 AND gates, n - 1 adders
💡 Tip

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.
🎯 END-TERM EXAM PREP

📝 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)