Adders & Arithmetic Hardware

From a full adder to a 4-bit ripple-carry adder, verified exhaustively, and what + becomes in hardware.

Addition is the most common arithmetic in hardware. A ripple-carry adder chains full adders, each one's carry out feeding the next one's carry in. Building one teaches module instantiation, generate loops and exhaustive verification.

A 4-bit ripple-carry adder

wire [4:0] c holds the five carries: c[0] is the carry in, c[4] the carry out.

genvar i is a loop variable that exists only while the design is being built (elaboration).

begin : stage names the loop body, so the instances are stage[0].fa, stage[1].fa, ...

Each full_adder gets bit i of a and b and the carry c[i], and produces c[i+1].

In practice: just write +

wire [7:0] sum = a + b; // a, b are 8-bit wire [8:0] sum = a + b;

The carry out is the 9th bit; an 8-bit result silently wraps on overflow.

How many full adders does an N-bit ripple-carry adder need, and what limits its speed?

N full adders. The carry ripples through all N stages, so the worst-case delay grows linearly with N.

How do you detect signed overflow when adding two signed numbers?

Overflow happened if both operands have the same sign and the result's sign differs: overflow = (a[n-1] == b[n-1]) && (sum[n-1] != a[n-1]). Equivalently, the carry into the sign bit differs from the carry out of it.