Wednesday, October 24, 2007

16bit comparer from 2bit comparer-s

Here is a cool idea, you can string a 2 bit comparer's together to make a big one... purely academic :-)
module compare_2bit(output A_eq_B, A_lt_B, A_gt_B, input [1:0] A, B, input A_eq_B_in, A_lt_B_in, A_gt_B_in);

assign A_eq_B = (A == B) & A_eq_B_in;
assign A_gt_B = (A==B) ? A_gt_B_in : A > B;
assign A_lt_B = (A==B) ? A_lt_B_in : (A < B);

endmodule

module compare_16bit(output X_eq_Y, X_lt_Y, X_gt_Y, input [15:0] X, Y);

wire[7:0] eq, lt, gt;
compare_2bit cp [7:0] (eq, lt, gt, X, Y, {eq[6:0],1'b1}, {lt[6:0],1'b0}, {gt[6:0],1'b0});

assign X_eq_Y = eq[7];
assign X_lt_Y = lt[7];
assign X_gt_Y = gt[7];

endmodule

No comments: