4-bit ALU in Verilog with a self-checking testbench
Design a 4-bit ALU with add, subtract, AND, OR, XOR and zero and carry flags, then write a testbench that checks every input combination on its own.
What this proves to recruiters
- You can write synthesisable Verilog.
- You verify designs automatically, not by staring at waves.
- You understand flags and two’s complement.
Skills you will use
- Verilog
- Combinational design
- Testbenches
- Two’s complement
What you need
Nothing to buy: this project only needs a computer and the free software below.
Free software
- Icarus Verilog
- GTKWave
- EDA Playground (in the browser)
Steps
- Define the ports: a[3:0], b[3:0], op[2:0], y[3:0], carry and zero.
- Write the ALU with one case statement on op, using a 5-bit sum to capture the carry.
- Set zero = (y == 0) outside the case statement.
- In the testbench, loop through all a, b and op values (16 × 16 × 5 = 1,280 cases).
- Compute the expected answer in the testbench and print an error if the ALU disagrees.
- Look at a few cases in GTKWave, then put the code and a short README on GitHub.
Make it stand out
- Add shift and compare operations.
- Make the width a parameter so the same code builds an 8-bit or 32-bit ALU.
Put it on your resume
Designed a parameterisable ALU in Verilog and verified all 1,280 input combinations with a self-checking testbench.
Replace each [x] with a number you measured. Real numbers make a line believable.
Keep going
This project fits stage 1, “Digital logic, properly”, of the RTL and digital design roadmap. See also how freshers get into FPGA design engineer jobs.