Comparator Dataflow Modeling
Comparator Dataflow Modeling
Comparator Dataflow Modeling
Dataflow modeling
module cmp(x,y,z,a,b);
input a,b;
output x,y,z;
assign x=(~a)&b;
assign y=((~a)&(~b))|(a&b);
assign z=a&(~b);
endmodule
Test Bench
module cmp_tb;
// Inputs
reg a;
reg b;
// Outputs
wire x;
wire y;
wire z;
cmp uut (
.x(x),
.y(y),
.z(z),
.a(a),
.b(b)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
end
endmodule
behavioral modeling
module cmp(x,y,z,a,b);
input a,b;
output x,y,z;
reg x,y,z;
always@ (a or b)
if (a>b)
begin
x=0;y=0;z=1;end
else if (a==b)
begin
x=0;y=1;z=0;end
else
begin
x=1;y=0;z=0;end
endmodule
Test Bench
module cmp_tb1;
// Inputs
reg a;
reg b;
// Outputs
wire x;
wire y;
wire z;
.x(x),
.y(y),
.z(z),
.a(a),
.b(b)
);
initial begin
// Initialize Inputs
a = 0;b = 0;#100;
a = 0;b = 1;#100;
a = 1;b = 0;#100;
a = 1;b = 1;#100;
end
endmodule