Below given is a verilog code for a comparator. The comparator receives two 4 bit input vectors. After receiving the input comparator has to assert one of its output pin, indicating whether the input strings are equal or in other case which one is greater than the other. The implementation has been done using assign block or continuous assignment statement.
module comparator_4_bit (a_gt_b, a_lt_b, a_eq_b, a,b);input [3 : 0] a,b;output a_gt_b, a_lt_b, a_eq_b;assign a_gt_b = (a > b);assign a_lt_b = (a < b);assign a_eq_b = (a == b);endmodule
Assign statement actually implements a combinational circuit, which produces an output 1 or logic high if a is greater than b at pin a_gt_b. Same is the case for a_lt_b and a_eq_b port pins.
0 comments:
Post a Comment