firmwareMIT

4-bit adder in Verilog

breadboardhub/4-bit-adder-in-verilog
verilogtestbenchbitadder
ShareXLinkedInFacebookRedditWhatsApp
B
Mike M
v1.0.0 · UpdatedNov 24, 2026 ·0 downloads ·0 forks
Verilog, with a testOpen in the chip playground
// A 4-bit adder with carry in and carry out.
// {cout, sum} is the 5-bit result of a + b + cin.
module adder4 (
  input  wire [3:0] a,
  input  wire [3:0] b,
  input  wire       cin,
  output wire [3:0] sum,
  output wire       cout
);
  assign {cout, sum} = a + b + cin;
endmodule
Description

Adds two 4-bit numbers with carry in and out. It comes with a test that builds with Yosys and runs in the browser. Set a to 9 and b to 8: sum shows 1 and cout lights, because 17 does not fit in 4 bits.

Cite this design
@design{breadboardhub/4-bit-adder-in-verilog,
  title = {4-bit adder in Verilog},
  author = {breadboardhub},
  url = {https://www.breadboardhub.com/breadboardhub/4-bit-adder-in-verilog},
  version = {1.0.0}
}