Problem: Implement Half Adder in Verilog
Objective
A Half Adder is a basic combinational circuit that performs the addition of two 1-bit binary numbers.
It produces two outputs:
- Sum (S) → XOR of inputs
- Carry (C) → AND of inputs
In this tutorial, you will design a half adder using Verilog and test it with all input combinations.
Explanation
The half adder cannot handle carry-in from previous additions (that’s why it’s called half).
It is the simplest building block for binary addition.
- Sum Equation:
S = A ⊕ B - Carry Equation:
C = A · B
Requirements
-
Create a Verilog module named
half_adderwith:- Two inputs:
a,b - Two outputs:
sum,carry
- Two inputs:
-
Implement the equations:
assign sum = a ^ b;assign carry = a & b;
-
Write a
testbenchmodule to verify the half adder:- Apply all 4 input combinations of
aandb(00, 01, 10, 11). - Check
sumandcarry.
- Apply all 4 input combinations of
Expected Truth Table
| a | b | sum | carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
No Waveform Data
Submit your Verilog code using Cmd+Enter to see the simulation results and waveform visualization.