You are on page 1of 6

Assignment-4

Name:Saurav Kumar Roll no:23UCC597

1)2 Input decoder


(i)Source Code
module binary_decoder2_1(
input a1,
input a2,
input e,
output [3:0] y
);
assign y[0]=e&(~a1&~a2);
assign y[1]=e&(~a1& a2);
assign y[2]=e&(a1&~a2);
assign y[3]=e&(a1&a2);
endmodule

(ii)Test Bench
module binary_decoder2_1_tb(

);
reg A1,A2,E;
wire [3:0] Y;
binary_decoder2_1 dut(
.a1(A1),
.a2(A2),
.e(E),
.y(Y)
);
integer i;
initial begin
for(i=0;i<8;i=i+1)
begin
{A1,A2,E}=i;
#10;
end
$finish;
end
endmodule
(iii)Waveform

(iv)Schematic
2)4 input decoder using 2 input decoder
(i)Source Code
module binary_decoder4_16(
input x3,x2,x1,x0,
input e,
output [15:0] y
);
wire [3:0] E;
binary_decoder2_1 a1(x3,x2,e,E);
binary_decoder2_1 a2(x1,x0,E[0],y[3:0]);
binary_decoder2_1 a3(x1,x0,E[1],y[7:4]);
binary_decoder2_1 a4(x1,x0,E[2],y[11:8]);
binary_decoder2_1 a5(x1,x0,E[3],y[15:12]);
endmodule

(ii)Test Bench
module binary_decoder4_16_tb(

);
reg X3,X2,X1,X0;
reg E;
wire [15:0] Y;
binary_decoder4_16 dut(.x3(X3),.x2(X2),.x1(X1),.x0(X0),.e(E),.y(Y));
integer j;
initial begin
for(j=0;j<32;j=j+1)
begin
{X3,X2,X1,X0,E}=j;
#10;
end
$finish;
end
endmodule
(iii)Waveform

(iv)Schematic
3)Even and Odd parity using 4 input decoder
(i)Source Code
module odd_and_even(
input E,
input x3,
input x2,
input x1,
input x0,
output EP,
output OP
);
wire [0:15] y;
binary_decoder4_16 t(x3,x2,x1,x0,E,y);
assign EP=y[15]|y[12]|y[10]|y[9]|y[6]|y[5]|y[3]|y[0];
assign OP=y[14]|y[13]|y[11]|y[8]|y[7]|y[4]|y[2]|y[1];
endmodule

(ii)Test Bench
module odd_and_even_tb();
reg X3,X2,X1,X0,e;
wire Ep,Op;
integer i;
odd_and_even dut( .E(e), .x3(X3), .x2(X2), .x1(X1), .x0(X0), .EP(Ep), .OP(Op));
initial begin
for(i=0;i<32;i=i+1)
begin
{e,X3,X2,X1,X0}=i;
#10;
end
$finish;
end
endmodule
(iii)Waveform

(iv)Schematic

You might also like