ECEdge

Exam: GATE 2027 exams are on 6, 7, 13, 14, 20 and 21 February 2027. Official GATE 2027 site

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

The ALU core and the testbench resultalways @(*) begin case (op) 3'd0: {carry, y} = a + b; 3'd1: {carry, y} = a - b; 3'd2: y = a & b; endcaseend$ vvp alu_tbChecked 1280 casesPASS: 0 mismatches
The testbench computes each answer itself, so the check runs in seconds.

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

  1. Define the ports: a[3:0], b[3:0], op[2:0], y[3:0], carry and zero.
  2. Write the ALU with one case statement on op, using a 5-bit sum to capture the carry.
  3. Set zero = (y == 0) outside the case statement.
  4. In the testbench, loop through all a, b and op values (16 × 16 × 5 = 1,280 cases).
  5. Compute the expected answer in the testbench and print an error if the ALU disagrees.
  6. 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.

More RTL and digital design projects

All 49 project ideas