Professional Documents
Culture Documents
To find comparison of magnitude of two 4bit numbers we have a similar procedure. Input A=AAAA: B-BBBB..
To examine whether A<B or vice-versa then firstly test MSB of both inputs. If MSB both the inputs are
different i.e.; if A, B, then A>B, & A<B in vice versa. If MSB are equal of both inputs, then go for next
consecutive bit and then compare next bit of both the inputs. A-B will Come in case of same inputs.
TRUTH TABLE
• TRUTH TABLE FOR 4-BIT MAGNITUDE COMPARATOR
PROGRAM
• VERILOG CODE:
module comparator(a, b, eq, lt, gt);
input [3:0] a, b;
output reg eq, lt, gt;
always @(a, b)
begin
if (a == b)
begin
eq = 1'b1;
CONTINUED….
lt = 1'b0;
gt = 1'b0;
end
else if (a > b)
begin
eq = 1'b0;
lt = 1'b0;
gt = 1'b1;
end
CONTINUED…..
else
begin
eq = 1'b0;
lt = 1'b1;
gt = 1'b0;
end
end
endmodule
OUTPUT:
CONCLUSION