Menu
Coddy logo textTech

Recap - Simple Comparator

Part of the Fundamentals section of Coddy's Verilog journey — lesson 54 of 90.

challenge icon

Challenge

A 2-bit comparator is a circuit that compares two 2-bit binary numbers and determines whether one is greater than, less than, or equal to the other.

What to do:

Build a 2-bit comparator using if-else statements.

How it works:

  • When a > b, greater should be 1, less and equal should be 0
  • When a < b, less should be 1, greater and equal should be 0
  • When a == b, equal should be 1, greater and less should be 0

Try it yourself

module comparator (
  input [1:0] a,
  input [1:0] b,
  output reg greater,
  output reg less,
  output reg equal
);
  
  always @(*) begin
    // TODO: Add if-else statements to compare a and b
    // Set greater = 1 if a > b
    // Set less = 1 if a < b
    // Set equal = 1 if a == b
  end
  
endmodule

All lessons in Fundamentals