Prev Problem
Next Problem

67. Decoder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module decoder_2to4 (
	input wire [1:0] X,
	input wire E,
	output [3:0] Y
);
	reg [3:0] Y_r;

	assign Y = Y_r;

	always @(X or E)
	begin
		if (E)
		begin
			case (X)
				2'b00:   Y_r = 4'b0001;
				2'b01:   Y_r = 4'b0010;
				2'b10:   Y_r = 4'b0100;
				default: Y_r = 4'b1000;
			endcase
		end
		else	
			Y_r = 4'b0000;
	end
endmodule
module decoder3to8 (
	input wire  [2:0] s,
	output wire [7:0] y
);
	decoder_2to4 en0 (.X(s[1:0]), .E(~s[2]), .Y(y[3:0]));
	decoder_2to4 en1 (.X(s[1:0]), .E(s[2]),  .Y(y[7:4]));
endmodule

 

Was this helpful?
Upvote
Downvote