A digital comparator is a circuit which compares two strings of equal sizes and asserts a signal bit output showing, whether the two strings are equal, or which one is greater than the other one. Given below is a code for comparator implementation in verilog. The comparator is able to compare 2-bit vectors placed at the input. The implementation has been done using continuous assignment "assign" statement.
module compare_2_bit (a_lt_b, a_gt_b, a_eq_b, a1, a0, b0' b1, c0, c1);input a1, a0, b1, b0;output a_lt_b, a_gt_b, a_eq_b;assign a_lt_b= (~a1)&b1|(~a1)&(~a0)&b0|(~a0)&b1&b0;assign a_gt_b= a1&(~b1)|a0&(~b1)&(~b0)|a1&a0&(~b0);assign a_eq_b= (~a1)&(~a0)&(~b1)&(~b0)|(~a1)&a0&(~b1)&b0|a1&a0&b1&b0|a1&(~a0)&b1&(~b0);endmodule
The implementation has been done using assign block, also known as continuous assignment statement. Each operator used inside the continuous statement has its gate-level counterpart available at the back-end. This enables easy translation (synthesis)of statement functionality into a physical circuit.