DLD MOD1.5
DLD MOD1.5
module ripple_carry_4_bit_tb();
reg [3:0]a,b;
reg cin;
wire [3:0]sum;
wire carry;
ripple_carry_4_bit U1(a,b,cin,sum,carry);
initial
begin
#0 a=4’b1010;b=4’b0011;cin=0;
#10 a=4’b1100; b=4’b0101; cin=1’b1;
end
initial
$monitor(“time=“,$time, “a=%b,b=%b,cin=%b,sum=%b,carry=%b”,a,b,cin,sum,carry);
initial
#30 $finish;
endmodule
2 BIT COMPARATOR AND TESTBENCH
module 2_Mag_Comp(input [1:0]a, b, output equal, module comparator_tb();
greater, lower ); reg [1:0]a,b;
reg greater, equal, lower; wire equal,greater,lower;
initial greater = 0, equal = 0, lower = 0;
always @ (a or b) Mag_Comp U1(a,b,equal,greater,lower);
begin initial
if (a < b) begin
begin #0 a=2’b01;b=2’b10;
greater = 0; equal = 0; lower = 1; #10 a=2’b11;b=2’b11;
end #10 a=2’b11; b=2’b01;
else if (a == b) end
begin initial
greater = 0; equal = 1; lower = 0; $monitor($time,”a=%b,b=%b,equal=%b,greater=%b,lower=
end %b”,a,b,equal,greater,lower);
else Initial
begin #50 $finish;
greater = 1; equal = 0; lower = 0; endmodule
end
end
endmodule
4:1 MULTIPLEXER & TEST BENCH
module mux4to1_tb( );
module mux4to1(i, s, y); reg [3:0] i;
input [3:0] i; reg [1:0] s;
input [1:0] s; wire y;
output reg y; mux4to1 g1(i, s, y);
always @ (*) initial
if (s==0) begin
y=i[0]; #0 s=2'b00; i=4'b0001;
else if (s==1) #10 s=2'b01; i=4'b0001;
y=i[1]; #10 s=2'b10; i=4'b0101;
else if (s==2) #10 s=2'b11; i=4'b1001;
y=i[2]; end
else initial
y=i[3]; $monitor ($time, "i = %b, s=%b, y=%b", i, s, y);
endmodule
initial
#100 $finish;
endmodule
8:1 MULTIPLEXER & TEST BENCH
module mux8to1_tb( );
module mux8to1(i, s, y); reg [7:0] i;
input [7:0] i; reg [2:0] s;
input [2:0] s; wire y;
output reg y; mux8to1 g1(i, s, y);
always @ (*) initial
begin begin
case (s) #0 s=3'b000; i=8'b10101010;
3'b000: y=i[0]; #10 s=3'b001; i=8'b10101010;
3'b001: y=i[1]; #10 s=3'b010; i=8'b10101010;
3'b010: y=i[2]; #10 s=3'b011; i=8'b10101010;
3'b011: y=i[3]; #10 s=3'b100; i=8'b10101010;
3'b100: y=i[4]; #10 s=3'b101; i=8'b10101010;
3'b101: y=i[5]; #10 s=3'b110; i=8'b10101010;
3'b110: y=i[6]; #10 s=3'b111; i=8'b10101010;
3'b111: y=i[7]; end
default: y=8'b00000000; initial
endcase $monitor ($time, "i = %b, s=%b, y=%b", i, s, y);
end
endmodule initial
#100 $finish;
endmodule