Recap - Simple Comparator
Part of the Fundamentals section of Coddy's Verilog journey — lesson 54 of 90.
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,greatershould be 1,lessandequalshould be 0 - When
a < b,lessshould be 1,greaterandequalshould be 0 - When
a == b,equalshould be 1,greaterandlessshould 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
endmoduleAll lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic