Concept Flow - Decoder design
Input bits
Decode input
Activate one output line
All other outputs are 0
End
A decoder takes input bits and activates exactly one output line based on the input value, setting all others to zero.
module decoder2to4(input [1:0] A, output reg [3:0] Y); always @(*) begin Y = 4'b0000; case(A) 2'b00: Y = 4'b0001; 2'b01: Y = 4'b0010; 2'b10: Y = 4'b0100; 2'b11: Y = 4'b1000; default: Y = 4'b0000; endcase end endmodule
| Step | Input A | Action | Output Y |
|---|---|---|---|
| 1 | 00 | Set Y=0000; case 00 matched | 0001 |
| 2 | 01 | Set Y=0000; case 01 matched | 0010 |
| 3 | 10 | Set Y=0000; case 10 matched | 0100 |
| 4 | 11 | Set Y=0000; case 11 matched | 1000 |
| 5 | Others | No match (default case) | 0000 |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| A | 00 | 00 | 01 | 10 | 11 | 11 |
| Y | 0000 | 0001 | 0010 | 0100 | 1000 | 1000 |
Decoder design in Verilog: - Input: n bits - Output: 2^n bits - Exactly one output bit is 1 based on input - Use case statement inside always block - Initialize output to zero before case - Outputs are one-hot encoded
always @(*) begin
case(in)
2'b00: out = 4'b0001;
2'b01: out = 4'b0010;
2'b10: out = 4'b0100;
2'b11: out = 4'b1000;
default: out = 4'b0000;
endcase
endWhat is the value of out when in = 2'b10?always @(*) begin
case(in)
3'b000: out = 8'b00000001;
3'b001: out = 8'b00000010;
3'b010: out = 8'b00000100;
3'b011: out = 8'b00001000;
3'b100: out = 8'b00010000;
3'b101: out = 8'b00100000;
3'b110: out = 8'b01000000;
// Missing case for 3'b111
endcase
endcase statement. Which approach correctly handles all inputs and ensures only one output bit is high at a time?Pass the test and this pattern moves unknown