| Status | Title | Difficulty | Tags |
|---|---|---|---|
A Half Subtractor is a combinational circuit that subtracts one 1-bit binary input (b) from another (a).
It produces two outputs:
In this tutorial, you will design a half subtractor using Verilog and test it with all input combinations.
The half subtractor handles subtraction of two bits only — it cannot handle borrow from a previous stage (that’s why it’s half).
Difference Equation:
D = a ⊕ b
Borrow Equation:
B = (~a) & b
(Borrow is needed when a = 0 and b = 1.)
half_subtractor with:
a, bdiff, borrowassign diff = a ^ b;assign borrow = (~a) & b;testbench module to verify:
00, 01, 10, 11).| a | b | diff | borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
testbench and inspect signals a, b, diff, borrow in waveforms.diff = a ⊕ b and borrow = (~a) & b for all inputs.a in the borrow equation.a - b directly in Verilog (not recommended for logic design tutorials).Submit your Verilog code using Cmd+Enter to see the simulation results and waveform visualization.