4-bit Adder with Carry

Easy · Arithmetic · Combinational Logic

Implement a 4-bit unsigned adder with carry-in and carry-out.

Ports

PortDirWidthMeaning
ainput4Unsigned operand, 0–15.
binput4Unsigned operand, 0–15.
cininput1Carry in (adds 0 or 1).
sumoutput4Low 4 bits of a + b + cin.
coutoutput1Carry out: bit 4 of a + b + cin.

Together, {cout, sum} is the full 5-bit result: {cout, sum} == a + b + cin, which ranges from 0 (0 + 0 + 0) to 31 (15 + 15 + 1). The circuit is purely combinational.

Examples

abcina+b+cincoutsum
340707
9701610
15011610
1515131115

Two ways to write it

  1. Behavioral. You may use +. The catch is expression width: in Verilog the width of

an addition is decided by its context, so a + b assigned to a 4-bit signal silently drops the carry. Concatenate the outputs on the left-hand side, {cout, sum} = ..., to give the expression a 5-bit context.

  1. Structural (the "ripple carry" adder). Chain four full adders. For bit i with carry

c[i] (where c[0] = cin):

The carry "ripples" from bit 0 to bit 3, which is why this structure is slow for wide adders (and why faster carry-lookahead adders exist).

Either approach is accepted.

Sign up free to solve 4-bit Adder with Carry in your browser.

More Arithmetic problems