24-Booth Multiplier, Behavioral Modeling-17!02!2023
24-Booth Multiplier, Behavioral Modeling-17!02!2023
24-Booth Multiplier, Behavioral Modeling-17!02!2023
initial initial
xor_out = in1 ^ in2; begin
and_out = a_in & b_in;
end
initial
begin
enable = 1’b0;
rst = 1’b0;
#100 rst = 1’b1;
#20 enable = 1’b1;
end
always statement
output clk_out;
reg clk_out;
always
#5 clk_out = ~clk_out;
initial
clk_out = 1’b1;
endmodule
Examples
2 x 1 multiplexer
module mux_2x1 (y, a, b, s);
output y;
input a, b, s;
reg y;
always @(a or b or s)
if (s==1) y = a;
else y = b;
endmodule.
Magnitude comparator
else if (a>b)
module comparator (a,b,eq,lt,gt);
begin
input [3:0] a, b; eq = 1’b0;
output reg eq,lt, gt; lt = 1’b0;
always @(a,b) gt = 1’b1;
begin end
else
if (a ==b)
begin
begin eq = 1’b0;
eq = 1’b1; lt = 1’b1;
lt = 1’b0; gt = 1’b0;
gt = 1’b0; end
end
end
endmodule
Test bench for comparator
module comparator_tb ();
reg [3:0] a, b;
wire eq, lt,gt;
comparator C1 (a,b,eq,lt,gt);
initial
begin
a = 4’b1100;
b = 4’b 1100;
#10;
a = 4’b0100;
b = 4’b 1100;
#10;
a = 4’b1000;
b = 4’b0010;
end
endmodule