Professional Documents
Culture Documents
Decoder
Decoder
B. Case statement
module decoder_2_4(a,b,w,x,y,z);
output w,x,y,z;
input a,b;
Behave
module decoder2_4 ( din ,dout );
endmodule
module decoder_2_to_4(
input a0,
input a1,
output d0,
output d1,
output d2,
output d3
);
not(an0,a0),(an1,a1);
and(d0,an0,an1),(d1,a0,an1),(d2,an0,a1),(d3,a0,a1
);
endmodule
3: 8 DECODER
module decoder3_to_8(
input x,
input y,
input z,
output d0,
output d1,
output d2,
output d3,
output d4,
output d5,
output d6,
output d7
);
and (d0,xn,yn,zn),(d1,xn,yn,z),(d2,xn,y,zn),(d3,xn,y,z),(d4,x,yn
,zn),(d5,x,yn,z),(d6,x,y,zn),(d7,x,y,z);
not (xn,x),(yn,y),(zn,z);
endmodule
input [2:0] I;
output [7:0] Y;
reg [7:0] Y;
always @ (I)
begin
else Y=8'b10000000;
end
endmodule
B. Case statement
input [2:0] I;
output [7:0] Y;
reg [7:0] Y;
always @ (I)
begin
case (I)
0 : Y=8'b00000001;
1 : Y=8'b00000010;
2 : Y=8'b00000100;
3 : Y=8'b00001000;
4 : Y=8'b00010000;
5 : Y=8'b00100000;
6 : Y=8'b01000000;
7 : Y=8'b10000000;
default : Y=8'b00000001;
endcase
end
endmodule
module decoder3_to_8(input x, input y, input z, output d0, output d1, output d2, output d3, output d4,
output d5, output d6, output d7);
and (d0,xn,yn,zn),(d1,xn,yn,z),(d2,xn,y,zn),(d3,xn,y,z),(d4,x,yn,zn),(d5,x,yn,z),(d6,x,y,zn),(d7,x,y,z);
endmodule
4:16 Decoder