// Different ways to write decoders //in always blocks module decoder(W, Y, En); input [1:0] W; input En; output [3:0] Y; reg [3:0] Y; always @(W or En) begin // concatenation {En, W} case({En, W}) 3'b100:begin Y = 4'b0001; end 3'b101: Y = 4'b0010; 3'b110: Y = 4'b0100; 3'b111: Y = 4'b1000; default: Y= 4'b0000; endcase end /*----- What do you think about this? --*/ /* Will the following code work correctly as a combinational decoder circuit? If yes, why? If not, why not? Find out! */ /*------- always@(En, W) begin if(En == 0) Y=4'b0000; else case(W) 2'b00: Y = 4'b0001; 2'b01: Y = 4'b0010; 2'b10: Y = 4'b0100; 2'b11: Y = 4'b1000; endcase end -------*/ /* And what about the following code, see carefully... */ /*--------- always@(En, W) begin if(En == 0) begin Y=4'b0000; end case(W) 2'b00: Y = 4'b0001; 2'b01: Y = 4'b0010; 2'b10: Y = 4'b0100; 2'b11: Y = 4'b1000; endcase end ------------*/ endmodule