COA Notes: Design of ALU

Nov 19, 2026·Pranesh Mahanta·21ECC301T — Computer Organization and Architecture

Arithmetic: adders, subtractors, multipliers, dividers and IEEE-754 — how the ALU is really built.

Contents
  1. ALU — the heart of the processor
  2. Half Adder
  3. Full Adder
  4. Full Subtractor
  5. Ripple Carry Adder
  6. Carry Look-ahead Adder (CLA)
  7. Binary Parallel Adder–Subtractor
  8. De Morgan's Theorems
  9. Unsigned Array Multiplier
  10. Shift-and-Add Multiplication (positive numbers)
  11. Booth's Algorithm (signed multiplication)
  12. Bit-Pair Recoding of Multipliers (fast multiplication)
  13. Carry-Save Addition of Summands
  14. Restoring Division
  15. Non-Restoring Division
  16. IEEE 754 Floating-Point Arithmetic

1ALU — the heart of the processor

The Arithmetic Logic Unit is a combinational circuit and the computational heart of every CPU — everything the processor does passes through it.

N-bit ALUAnBnCarry inSELECTYResult CCarry outZEROOVERFLOW
ALU symbol — A, B in, function select, Result C out with status flags

The design issues of a 1-bit ALU slice: the control signals S₁ S₀ choose which operation the slice performs, and a 4×1 multiplexer picks the result. A 4-bit ALU is built by combining four 1-bit slices (carries rippling between the ADD blocks); a 16-bit ALU repeats the same idea sixteen times.

ANDORXORADDA, B4×1MUXS₁S₀FCin (for ADD)S₁ S₀ = 00 → AND 01 → OR 10 → XOR 11 → ADD
1-bit ALU slice — four function blocks feeding a 4×1 MUX selected by S₁ S₀
S₁S₀ = 00 → A AND B  ·  01 → A OR B  ·  10 → A XOR B  ·  11 → A ADD B

2Half Adder

A combinational logic circuit with two inputs (A, B) and two outputs (Sum, Carry), designed to add two single-bit binary numbers.

Adders are the basic building blocks of the ALU. In the half adder the sum output is 1 whenever an odd number of inputs are 1 — exactly the XOR behaviour — and the carry is 1 only when both inputs are 1, which is the AND behaviour.

Sum  S = A ⊕ B     Carry  C = A · B
ABS (sum)C (carry)
0000
0110
1010
1101
ABSCS = A ⊕ BC = A · BXORAND
Half adder — one XOR for the sum, one AND for the carry

Limitation: the half adder has no carry-in input, so the carry of a previous addition cannot be included. It therefore cannot be chained to add multi-bit numbers — that job needs the full adder.

Worked problem
“If A and B are the inputs of a half adder, the sum is given by ______”

A ⊕ B (XOR) — option (c).

3Full Adder

Developed to overcome the drawback of the half adder: it adds three one-bit inputs — A, B and the carry-in Cin — and produces Sum and Carry-out.

S = A ⊕ B ⊕ Cin
Cout = A·B + Cin·(A ⊕ B)   (= AB + BCin + ACin)
ABCinSCout
00000
00110
01010
01101
10010
10101
11001
11111
ABCinSCoutXORXORANDANDORS = A ⊕ B ⊕ Cin Cout = A·B + Cin·(A ⊕ B)
Full adder — two XORs (sum path), two ANDs + OR (carry path)

A full adder equals two half adders + one OR gate: the first HA adds A and B, the second HA adds that sum to Cin, and the OR merges the two partial carries. Its delay is about two gate levels, and cascading n full adders gives the n-bit ripple carry adder.

Worked problem
“Explain a Full adder Circuit.”

Write it in this order: (1) definition (3 inputs A, B, Cin; 2 outputs S, Cout) → (2) truth table (8 rows) → (3) Boolean expressions → (4) gate diagram → (5) note that two HAs + OR make one FA. Everything above is the answer.

4Full Subtractor

The subtraction counterpart of the full adder: computes A − B − Bin producing Difference D and Borrow-out Bout.

The difference bit has exactly the same pattern as the full-adder sum — XOR of all three inputs. The borrow is 1 when B is larger than what is available: either A is 0 and B is 1, or the incoming borrow arrives while A ⊕ B is 0 (both bits equal).

D = A ⊕ B ⊕ Bin
Bout = A′·B + Bin·(A ⊕ B)′
ABBinDBout
00000
00111
01011
01101
10010
10100
11000
11111
ABBinDBoutXORXORNOTNOTANDANDORD = A ⊕ B ⊕ Bin Bout = A′·B + Bin·(A ⊕ B)′
Full subtractor — same XOR chain as the FA; borrow from two ANDs + OR

Exam shortcut: D of a full subtractor = S of a full adder. Only the borrow equation differs from the carry equation. With the XOR-plus-mode-line trick (next but one section) the same adder hardware performs subtraction, which is why real ALUs do not keep separate subtractor circuits.

Worked problem
“Explain a Full subtractor Circuit.”

Definition → truth table → expressions D and Bout → diagram, exactly mirroring the full-adder answer. Mention that the borrow logic treats “A < B” cases.

5Ripple Carry Adder

An n-bit adder made by cascading n full adders — the carry of each stage “ripples” into the next stage, so addition becomes a serial process.

  Carry ripple example (4-bit):
      Cout  A₃B₃ A₂B₂ A₁B₁ A₀B₀
       1    1    0    1    1     A = 1011 (11)
            1    1    0    1     B = 1101 (13)
      --------------------------
      1 1   0    0    0    0     Sum = 11000 (24)
FA₀A₀ B₀S₀C1FA₁A₁ B₁S₁C2FA₂A₂ B₂S₂C3FA₃A₃ B₃S₃Cin = 0CoutCarry ripples FA₀ → FA₃ : worst case ≈ 10 ns per FA → 40 ns for 4 bitsDelay grows linearly with n — the bottleneck of ripple addition
4-bit ripple carry adder — carry chain is the critical path
Worst-case delay ≈ 10 ns per FA → 4-bit adder ≈ 40 ns. Delay grows linearly with n (≈ 2n gate levels) — the bottleneck of ripple addition.
Worked problem
“Explain the Ripple carry adder with suitable example.”

Definition → how carry ripples (points above) → 4-bit cascade diagram → the 1011 + 1101 worked example → delay discussion.

Worked problem
“State the limitations of the Ripple carry Adder / suggest a suitable adder.”

Limitations: (1) each full adder must wait for its carry-in from the previous stage → large propagation time; (2) delay increases with the number of bits, so RCAs are extremely slow when adding many bits; (3) the worst-case path is the carry chain itself. Suitable replacement: the Carry Look-ahead Adder — it generates every carry simultaneously from P/G signals in a constant number of gate delays (slightly costlier hardware).

6Carry Look-ahead Adder (CLA)

An improved, fast parallel adder that solves the carry-propagation problem by calculating every carry in advance, directly from the input bits.

In every bit position two internal signals are defined from the operands alone — they settle after a single gate delay:

Carry Propagate: Pi = Ai ⊕ Bi   (if Pi=1, the input carry passes through: Ci+1 = Ci)
Carry Generate: Gi = Ai·Bi   (if Gi=1 a carry is produced whatever Ci is)

Sum: Si = Pi ⊕ Ci   ·   Carry: Ci+1 = Gi + PiCi

Expanding Ci+1 = Gi + PiCi repeatedly expresses every carry in terms of the inputs only — so all of them are produced in parallel:

C₁ = G₀ + P₀C₀
C₂ = G₁ + P₁G₀ + P₁P₀C₀
C₃ = G₂ + P₂G₁ + P₂P₁G₀ + P₂P₁P₀C₀
C₄ = G₃ + P₃G₂ + P₃P₂G₁ + P₃P₂P₁G₀ + P₃P₂P₁P₀C₀
Pᵢ = Aᵢ⊕Bᵢ (propagate), Gᵢ = AᵢBᵢ (generate)Pᵢ, Gᵢ stageCarry Look-ahead Generator(built from AND-OR logic, IC 74182)C₀C₁ C₂ C₃ C₄Sum XORs: Sᵢ = Pᵢ ⊕ CᵢS₃ S₂ S₁ S₀every carry ready after 3 gate delays,every sum after 4 — independent of n
CLA structure — P/G stage, look-ahead generator (IC 74182), sum XORs

Speed: P values are valid one XOR-gate delay and G values one AND-gate delay after the operands. Every carry Ci+1 is then ready in 3 gate delays and every sum Si in 4 gate delays — independent of n, against ≈ 2n gate delays (10 ns per FA → 40 ns) for the ripple adder.

Worked example (learn this — it answers “with suitable example”):

bit iAi BiPi GiCiSi
01 010C₀ = 01
11 101C₁ = 00
20 110C₂ = 10
31 010C₃ = 10

A = 1011 (11), B = 0110 (6), C₀ = 0 → carries C₁C₂C₃C₄ = 0 1 1 1, sum = 1 0001 (17) ✓. Check: C₂ = G₁ + P₁C₁ = 1; C₃ = G₂ + P₂C₂ = 0 + 1·1 = 1; C₄ = G₃ + P₃C₃ = 0 + 1·1 = 1.

4-bit CLA gate-level circuit
Gate-level 4-bit CLA from the class slides (reused) — the encircled part is the look-ahead carry generator

• fast look-ahead carry circuits reduce propagation delay (option b). • carry-look-ahead logic uses the concept of generating and propagating carries (option c).

Worked problem
“Explain / Design a 4-bit CLA and show it is faster than the ripple adder.”

Write: definition → Pi, Gi equations → expanded C₁…C₄ → block/gate diagram (above) → delay comparison table → the 1011 + 0110 example → closing line: CLA carries come in 3–4 gate delays regardless of n, the ripple adder needs ≈ 2n levels (40 ns for 4 bits); cost is extra AND-OR hardware that grows complicated as bits increase.

7Binary Parallel Adder–Subtractor

One circuit that performs both addition and subtraction, switched by a mode control signal M.

Each of B's bits passes through an XOR gate whose other input is M. The XOR truth table makes it work: one input 0 → output equals the second input; one input 1 → output is the complement of the second input.

MB0A0FA0S0C1B1A1FA1S1C2B2A2FA2S2C3B3A3FA3S3C₀ = MCoutM = 0 : Bᵢ ⊕ 0 = Bᵢ , C₀ = 0 → A + BM = 1 : Bᵢ ⊕ 1 = Bᵢ′ , C₀ = 1 → A + B̄ + 1 = A − B (2's complement)XOR rule: one input 0 → passes the other; one input 1 → complements it
4-bit adder–subtractor — XOR chain on B, and C₀ tied to M
M = 0 : Bi ⊕ 0 = Bi, C₀ = 0 → A + B
M = 1 : Bi ⊕ 1 = Bi′, C₀ = 1 → A + B′ + 1 = A − B  (2's-complement subtraction)
Worked problem
“Design an 8-bit Adder/Subtractor and explain the output for 78 + 12 and 78 − 12.”

Design: 8 full adders in cascade, an XOR gate on every B input, all XOR second inputs tied to M, and C₀ = M. The final carry-out C₈ is ignored in subtraction mode.

Addition (M = 0):
  A  = 78 = 0100 1110
  B  = 12 = 0000 1100
  ----------------------
  S  =       0101 1010  = 90   (C₈ = 0)

Subtraction (M = 1):  B is XORed with 1, C₀ = 1
  B ⊕ M = 1111 0011   (1's complement of 12)
  A + B′ + C₀ = 0100 1110 + 1111 0011 + 1
              = 1 0100 0010   → C₈ = 1 (discarded)
  Result = 0100 0010 = 66 ✓  (78 − 12)

8De Morgan's Theorems

A very powerful tool of digital design used to solve and transform Boolean expressions: the complement of a product equals the sum of the complements, and the complement of a sum equals the product of the complements.

Theorem 1: (A · B)′ = A′ + B′ — NAND ≡ Bubbled OR
Theorem 2: (A + B)′ = A′ · B′ — NOR ≡ Bubbled AND
ABY = (A·B)′≡A′B′Y = A′ + B′NAND = Bubbled ORABY = (A+B)′≡A′B′Y = A′·B′NOR = Bubbled AND
Both theorems as gate equivalences — NAND = bubbled OR, NOR = bubbled AND

Verification of Theorem 1 (LHS and RHS agree in every row):

ABA·B(A·B)′A′B′A′+B′
0001111
0101101
1001011
1110000

Verification of Theorem 2:

ABA+B(A+B)′A′B′A′·B′
0001111
0110100
1010010
1110000

Applications: with De Morgan's laws any Boolean expression can be built using only NAND or only NOR gates — one universal gate type for the whole circuit, which makes hardware design cheaper. The laws are also used in verifying SAS code, across computer and electrical engineering, and in Java programming.

9Unsigned Array Multiplier

The usual long multiplication we do in decimal applies to binary too: multiplying two n-bit numbers gives a 2n-bit product.

    B₃B₂B₁B₀
              1 1 0 1        13
        ×       1 1 0        6
        ─────────────────
              0 0 0 0        ← A₀ partial product (×1)
            1 1 0 1          ← A₁ partial product (×2, shifted)
          1 1 0 1            ← A₂ partial product (×4, shifted)
        ─────────────────
        1 0 0 1 1 1 0     = 78 ✓
a₁a₀ × b₁b₀ — each partial product is the AND of one A bit and one B bita₀ b₁a₁ b₀a₁ b₁a₀ b₀HA₁HA₂P₁P₀P₂P₃LSB P₀ needs no adder — it is the direct AND-gate output
2 × 2 array multiplier — AND gates form partial products, two HAs add them

• the standard method used for binary multiplication (of signed numbers) is Booth's Algorithm (option b). • in 110 × 1000 the operands are treated as n-bit quantities — 110 is padded to 0110, so n = 4 (option c).

10Shift-and-Add Multiplication (positive numbers)

Hardware version of paper-and-pencil multiplication: n cycles of “add the multiplicand if the multiplier bit is 1, then shift right”.

B (Multiplicand)n bitsAdder / ALUA (Product)Q (Multiplier)Write (Add result)Shift rightQ₀Controlsequencingn cycles: Q₀ = 1 → A ← A + B ; then shift A,Q right one bitAfter n cycles the 2n-bit product sits in A·Q
Shift-and-add hardware — B, ALU/adder, A (product), Q (multiplier), control
Worked problem
1100 × 0100
CycleCAQBOperation
00000001001100Initialise  (B = multiplicand, Q = multiplier)
0000001001100Q0 = 0 → No add
0000000101100Shift right C,A,Q
0000000101100Q0 = 0 → No add
0000000011100Shift right C,A,Q
30110000011100Q0 = 1 → Add B to A
0011000001100Shift right C,A,Q
0011000001100Q0 = 0 → No add
0001100001100Shift right C,A,Q
Product = A · Q = 00110000= 48 ✓

B = 1100 (12), Q = 0100 (4) → product 0011 0000 = 48. Only one addition happens (when Q₀ = 1 in cycle 3) — the two shifts before it pull that 1 up to Q₀.

Worked problem
10 × 9
CycleCAQBOperation
00000010011010Initialise  (B = multiplicand, Q = multiplier)
10101010011010Q0 = 1 → Add B to A
0010101001010Shift right C,A,Q
0010101001010Q0 = 0 → No add
0001010101010Shift right C,A,Q
0001010101010Q0 = 0 → No add
0000101011010Shift right C,A,Q
40101101011010Q0 = 1 → Add B to A
0010110101010Shift right C,A,Q
Product = A · Q = 01011010= 90 ✓

B = 1010 (10), Q = 1001 (9) → product 0101 1010 = 90.

Worked problem
11 × 13 by Shift-and-Add
CycleCAQBOperation
00000010111101Initialise  (B = multiplicand, Q = multiplier)
10110110111101Q0 = 1 → Add B to A
0011011011101Shift right C,A,Q
21001111011101Q0 = 1 → Add B to A
0100111101101Shift right C,A,Q
0100111101101Q0 = 0 → No add
0010011111101Shift right C,A,Q
41000111111101Q0 = 1 → Add B to A
0100011111101Shift right C,A,Q
Product = A · Q = 10001111= 143 ✓

B = 1101 (13), Q = 1011 (11) → product 1000 1111 = 143; at the end both A and Q hold the result.

11Booth's Algorithm (signed multiplication)

A powerful algorithm for signed (two's-complement) multiplication: it treats positive and negative operands uniformly and generates a 2n-bit product.

Idea: represent the multiplier as a difference of two numbers so the number of additions shrinks — e.g. 30 = 11110₂ = +32 − 2 → recoded +1 0 0 0 −1 0: add M once, subtract M once instead of adding four times. More examples: 200 = 011001000₂ → +1 0 −1 0 +1 −1 0 0 (= 256 − 32 + 8 − 4).

Inspect (Q₀ , Q₋₁) each cycle:
0 1 → A ← A + M  ·  1 0 → A ← A − M  ·  0 0 / 1 1 → nothing
then arithmetic shift right A, Q, Q₋₁  ·  repeat n times
Recode table (bi , bi−1): 00 → 0 · 01 → +1 · 10 → −1 · 11 → 0
MMultiplicandAdd / SubAQresult → AShift right A, Q, Q₋₁Q₀ Q₋₁Controladd / subtractBooth recodes the multiplier on the fly — 00/11 shift, 10 → −M, 01 → +M
Booth hardware — same A/Q/M registers; Q₀ Q₋₁ drive the add/subtract choice
STARTA = 0 , Q₋₁ = 0 , Count = nM = Multiplicand , Q = MultiplierQ₀ Q₋₁ = ?1 0A ← A − M0 1A ← A + M0 0 / 1 1 → no opShift right A,Q,Q₋₁Count ← Count − 1Count = 0?NoYesENDProduct in A, Q (2n bits)
Booth's algorithm flowchart

Efficiency: Booth reduces additions for “good” multipliers — alternating patterns need 4 additions against 8 for plain shift-and-add; ordinary patterns 7 vs 9. But it can make it worse: for isolated 1s the recoded multiplier is all ±1s and Booth takes 16 operations against 8. On average there is no big speed gain — the real win is uniform handling of negative numbers.

Worked problem
Booth: 1011 × 0011

M = 1011 = −5 (multiplicand), Q = 0011 = +3 (multiplier), n = 4, A = 0000, Q₋₁ = 0:

CycleQ₀ Q₋₁OperationA after opAQQ₋₁
——Initialise—000000110
110A ← A − M0101001010011
211no add / sub0010000101001
301A ← A + M1100111000100
400no add / sub1110111100010
After n cycles → product = A · Q = 11110001= -15 ✓

1111 0001 in 8-bit two's complement = −15 ✓ (−5 × 3).

Worked problem
Booth: (−7) × (+6)

M = 1001 = −7, Q = 0110 = +6, n = 4:

CycleQ₀ Q₋₁OperationA after opAQQ₋₁
——Initialise—000001100
100no add / sub0000000000110
210A ← A − M0111001110011
311no add / sub0011000111001
401A ← A + M1010110101100
After n cycles → product = A · Q = 11010110= -42 ✓

1101 0110 = −42 ✓. (Check: 11010110 = −128+64+16+4+2 = −42.)

• binary multiplication → Booth's Algorithm. • a machine-language instruction format consists of operation code field & operand field. • in 19 × 4 the 4 is the multiplier. • Booth's algorithm is applied on binary (two's-complement) numbers.

12Bit-Pair Recoding of Multipliers (fast multiplication)

Derived directly from Booth: group the Booth-recoded multiplier bits in pairs — this halves the maximum number of summands to n/2.

Key observation: the pair (+1, −1) equals (0, +1) — instead of subtracting M at position i and adding M at i+1, just add M at position i. In the same way (+1, 0) ≡ (0, +2) and (−1, +1) ≡ (0, −1). Each pair (bi+1 bi) together with the bit to its right bi−1 maps to one summand:

bᵢ₊₁bᵢbᵢ₋₁RecodedSummand
0000—
001+1+M
010+1+M
011+2+2M
100−2−2M
101−1−M
110−1−M
1110—
0b70b60b51b41b30b21b11b027 =rightrightrightright−1−1+20pairs (bᵢ₊₁ bᵢ , bᵢ₋₁) → one summand each → n/2 summands max27 recodes as −1·M + (−1)·4M + (+2)·16M
Grouping the multiplier bits of 27 into overlapping pairs

Why faster: bit-pair recoding reduces the summands by a factor of 2 compared with plain multiplication, each summand still costs one add, and the final product can be produced with a carry-look-ahead adder. Combined with carry-save addition (next section) this is the standard “fast multiplication” recipe.

Worked problem
Bit-pair recoding: (−11) × (+27)

Multiplier 27 = 00011011 → bit-pair recoding:

Pair (bᵢ₊₁ bᵢ , bᵢ₋₁)Position iValue
1 1 , 00-1
1 0 , 12-1
0 1 , 14+2
0 0 , 06+0
0 0 , 08+0

Summands (multiplicand M = -11; negative summands written in 2's complement, 12 bits):

Recoded termSummand (12 bits)DecimalRunning sum
-1 × M × 20000000001011+11000000001011
-1 × M × 22000000101100+44000000110111
+2 × M × 24111010100000-352111011010111
Product = 111011010111= -297 ✓
Worked problem
12 × (−15)

Multiplier -15 = 11110001 → bit-pair recoding:

Pair (bᵢ₊₁ bᵢ , bᵢ₋₁)Position iValue
0 1 , 00+1
0 0 , 02+0
1 1 , 04-1
1 1 , 16+0
1 1 , 18+0

Summands (multiplicand M = 12; negative summands written in 2's complement, 11 bits):

Recoded termSummand (11 bits)DecimalRunning sum
+1 × M × 2000000001100+1200000001100
-1 × M × 2411101000000-19211101001100
Product = 11101001100= -180 ✓
Worked problem
(−13) × (+21)

Multiplier 21 = 00010101 → bit-pair recoding:

Pair (bᵢ₊₁ bᵢ , bᵢ₋₁)Position iValue
0 1 , 00+1
0 1 , 02+1
0 1 , 04+1
0 0 , 06+0
0 0 , 08+0

Summands (multiplicand M = -13; negative summands written in 2's complement, 12 bits):

Recoded termSummand (12 bits)DecimalRunning sum
+1 × M × 20111111110011-13111111110011
+1 × M × 22111111001100-52111110111111
+1 × M × 24111100110000-208111011101111
Product = 111011101111= -273 ✓
Worked problem
15 × (−11)

Multiplier -11 = 11110101 → bit-pair recoding:

Pair (bᵢ₊₁ bᵢ , bᵢ₋₁)Position iValue
0 1 , 00+1
0 1 , 02+1
1 1 , 04-1
1 1 , 16+0
1 1 , 18+0

Summands (multiplicand M = 15; negative summands written in 2's complement, 11 bits):

Recoded termSummand (11 bits)DecimalRunning sum
+1 × M × 2000000001111+1500000001111
+1 × M × 2200000111100+6000001001011
-1 × M × 2411100010000-24011101011011
Product = 11101011011= -165 ✓
Worked problem
“Fast multiplication: bit-pair recoding of multipliers” (essay plan)

Booth recap → the (+1,−1) ≡ (0,+1) observation → the full bit-pair table → the 27 example above → efficiency: ≤ n/2 summands (Booth/plain: up to n), fewer additions, works with carry-save addition for further speed-up.

13Carry-Save Addition of Summands

A carry-save adder (CSA) — also called a 3-2 adder — adds three binary numbers to two numbers in one full-adder delay, without propagating any carry.

Worked example — summands of 1101 × 1011 (13 × 11 = 143):

SummandBinary (8 bits)
A (×1)0000 1101
B (×2)0001 1010
C (×4)0000 0000
D (×8)0110 1000
LevelInputsS vectorC vector
CSA₁A, B, C0001 01110001 0000
CSA₂S₁, C₁, D0110 11110010 0000
CPAS₂ + C₂1000 1111 = 143 ✓
ABCDCSA₁S₁C₁CSA₂S₂C₂CPA (CLA)Producteach level = 1 full-adder delaycarry is saved, not rippled
Carry-save tree: three vectors in → two out per level; final CPA gives the product
Ripple-carry array multiplier — every row waits for the previous row's carries
Ripple-carry array multiplier — every row waits for the previous row's carries (diagram reused from the class slides)
Carry-save array multiplier — rows produce saved S/C vectors, only the last adder ripples
Carry-save array multiplier — rows produce saved S/C vectors, only the last adder ripples (diagram reused from the class slides)

Compare: in the ripple-carry array each row of adders must wait for the carry of the row above it; in the carry-save array every row costs one FA delay and the carries are saved for the final adder — a big speed-up when adding many summands.

Worked problem
“Explain the Carry Save Adder with suitable example.”

Definition (3-2 adder, no carry propagation) → S and C vector idea → the 1101 × 1011 worked example → tree diagram → closing: final add with CLA.

14Restoring Division

Integer division based on longhand division: shift the partial remainder left, subtract the divisor, and if the result went negative, restore it by adding the divisor back.

A (n+1 bits)partial remainderQ (Dividend)→ becomes quotientAdd / SubMDivisorControlresult → Ashift leftSubtraction done via 2's complement — extra sign bit at the left of A and M
Division hardware — A (n+1 bits), Q, divisor M; subtraction via 2's complement
STARTA = 0 , Q = DividendM = Divisor , Count = nShift left A, QA ← A − MA ≥ 0 ?Yesq₀ ← 1(keep result)Noq₀ ← 0A ← A + M (restore)Count ← Count − 1Count = 0?NoYesQ = Quotient, A = Remainder
Restoring-division flowchart
Worked problem
Restoring: 1010 ÷ 0100 (10 ÷ 4)
CycleA after SHLQ (q₀ slot)A − MActionAQ
000001010—Initialise  (M = 0100)00001010
1000101001101A < 0 → q₀ = 0, restore A00010100
2001010001110A < 0 → q₀ = 0, restore A00101000
3010100000001A ≥ 0 → q₀ = 100010001
4001000101110A < 0 → q₀ = 0, restore A00100010
Quotient = Q = 0010 (2), Remainder = A = 0010 (2) ✓
Worked problem
Restoring: 1011 ÷ 0101 (11 ÷ 5)
CycleA after SHLQ (q₀ slot)A − MActionAQ
000001011—Initialise  (M = 0101)00001011
1000101101100A < 0 → q₀ = 0, restore A00010110
2001011001101A < 0 → q₀ = 0, restore A00101100
3010110000000A ≥ 0 → q₀ = 100001001
4000100101100A < 0 → q₀ = 0, restore A00010010
Quotient = Q = 0010 (2), Remainder = A = 0001 (1) ✓
Worked problem
restoring vs non-restoring (half of the answer)

Restoring: after every subtraction the negative result is undone (A + M), so a cycle can need two operations; q₀ = 1 only when A − M ≥ 0. Non-restoring: never restores, next cycle adds instead — see the next section for the other half of the comparison.

15Non-Restoring Division

Improves restoring division by never adding the divisor back: if A goes negative, the next cycle simply adds M instead of subtracting — one operation per cycle.

Repeat n times (after shifting A, Q left):
A ≥ 0 → A ← A − M, q₀ ← 1  ·  A < 0 → A ← A + M, q₀ ← 0
After the last cycle: if A < 0 → A ← A + M (final correction)
STARTA = 0 , Q = DividendM = Divisor , Count = nShift left A, QA < 0 ?YesA ← A + MNoA ← A − MA < 0 ?Yesq₀ ← 0Noq₀ ← 1Count ← Count − 1Count = 0?NoYesA < 0 ? → A ← A + M
Non-restoring flowchart — sign of A drives add or subtract
Worked problem
Non-restoring: 1000 ÷ 0010 (8 ÷ 2)
CycleA after SHLSign?OperationA after opq₀Q
00000—Initialise  (M = 0010, M′ = 2's compl.)0000—1000
10001A ≥ 0A ≥ 0 ← A = A − M111100000
21110A ≥ 0A < 0 ← A = A + M000000001
30000A ≥ 0A ≥ 0 ← A = A − M111000010
41100A ≥ 0A < 0 ← A = A + M111000100
final A < 0 → correction A ← A + MQuotient = 0100 (4), Remainder = 0000 (0) ✓
Worked problem
Non-restoring: 1000 ÷ 0011 (8 ÷ 3)
CycleA after SHLSign?OperationA after opq₀Q
00000—Initialise  (M = 0011, M′ = 2's compl.)0000—1000
10001A ≥ 0A ≥ 0 ← A = A − M111000000
21100A ≥ 0A < 0 ← A = A + M111100000
31110A ≥ 0A < 0 ← A = A + M000100001
40010A ≥ 0A ≥ 0 ← A = A − M111100010
final A < 0 → correction A ← A + MQuotient = 0010 (2), Remainder = 0010 (2) ✓

Here the final A is negative, so the correction A ← A + M is applied before reading the remainder.

Worked problem
full comparison table
RestoringNon-restoring
After negative subtractionAdds M back (restore) Keeps it; next cycle adds M
Operations per cycleUp to 2 (subtract + restore) Exactly 1 (add or subtract)
Quotient bit ruleq₀ = 1 iff A − M ≥ 0 q₀ = 1 iff A ≥ 0 after the op
End correctionNot needed A ← A + M if final A < 0
SpeedSlowerFaster (fewer adds)
ComplexitySimpler controlSlightly trickier control

16IEEE 754 Floating-Point Arithmetic

The IEEE Standard for Floating-Point Arithmetic (established 1985) is the common representation of real numbers on computers — Intel PCs, Macs, most Unix platforms.

Three basic components:

SingleSExponent (8)Mantissa (23)bias 127DoubleSExp (11)Mantissa (52)bias 1023value = (−1)ˢ × 1.mantissa × 2^(exponent − bias)
Single (1-8-23, bias 127) and double (1-11-52, bias 1023) formats

Worked example — represent 85.125:

85.125 = 1010101.001₂ = 1.010101001 × 2⁶

Single precision:  biased exponent = 127 + 6 = 133 = 1000 0101
                   mantissa        = 0101 0100 1 + zeros → 23 bits
  IEEE 754 single = 0 | 10000101 | 01010100100000000000000
                  = 42AA 4000 (hex)

Double precision:  biased exponent = 1023 + 6 = 1029 = 100 0000 0101
  IEEE 754 double = 0 | 10000000101 | 010101001 + zeros → 52 bits
                  = 4055 4800 0000 0000 (hex)

Special (reserved) values:

ExponentMantissaMeaning
all 00Zero (±0 — distinct bit patterns, both compare equal)
all 0≠ 0Denormalised number — no assumed leading 1
all 10Infinity — sign bit picks +∞ or −∞
all 1≠ 0NaN (Not a Number) — an error / undefined value

Ranges: five zones a single-precision number cannot represent — negative overflow (below −(2 − 2⁻²³) × 2¹²⁷), negative underflow (between −2⁻¹⁴⁹ and 0), zero, positive underflow (below 2⁻¹⁴⁹), positive overflow (above (2 − 2⁻²³) × 2¹²⁷). Overflow means the value grew too large to represent (serious); underflow is only a loss of precision, closely approximated by zero (less serious). The effective range is symmetric around zero: single ≈ ±1038.53, double ≈ ±10308.25.