Challenge - 5 Problems
Decoder Design Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this 2-to-4 decoder?
Given the following Verilog code for a 2-to-4 decoder, what will be the output
y when a = 2'b10?Verilog
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
Attempts:
2 left
💡 Hint
Look at the case statement and match the input
a to the output y.✗ Incorrect
The decoder sets only one bit high corresponding to the binary input. For input 2'b10, the output is 4'b0100.
❓ Predict Output
intermediateOutput of 3-to-8 decoder with enable low
Consider this 3-to-8 decoder with an active-high enable signal. What is the output
y when en = 0 and a = 3'b101?Verilog
module decoder3to8(input [2:0] a, input en, output reg [7:0] y); always @(*) begin if (en) begin y = 8'b00000000; y[a] = 1'b1; end else begin y = 8'b00000000; end end endmodule
Attempts:
2 left
💡 Hint
Check what happens when enable is low.
✗ Incorrect
When enable is 0, the output is forced to all zeros regardless of input.
🔧 Debug
advancedIdentify the error in this 4-to-16 decoder code
This Verilog code is intended to implement a 4-to-16 decoder. What error will occur when compiling or simulating this code?
Verilog
module decoder4to16(input [3:0] a, output reg [15:0] y); always @(*) begin y = 16'b0; case(a) 4'b0000: y[0] = 1'b1; 4'b0001: y[1] = 1'b1; 4'b0010: y[2] = 1'b1; // Missing other cases endcase end endmodule
Attempts:
2 left
💡 Hint
Look at the case statement coverage.
✗ Incorrect
The case statement does not cover all possible 4-bit inputs, causing a synthesis warning about incomplete cases.
📝 Syntax
advancedWhich option causes a syntax error in this decoder code?
Which of the following Verilog code snippets for a 2-to-4 decoder will cause a syntax error?
Attempts:
2 left
💡 Hint
Check for missing semicolons and proper statement endings.
✗ Incorrect
Option A is missing a semicolon after
y = 4'b0000, causing a syntax error.🚀 Application
expertHow many outputs are high for input 3'b011 in this priority decoder?
This Verilog code implements a 3-to-8 priority decoder. For input
a = 3'b011, how many bits in output y will be high (1)?Verilog
module priority_decoder3to8(input [2:0] a, output reg [7:0] y); always @(*) begin y = 8'b00000000; if (a[2]) y[7] = 1'b1; else if (a[1]) y[3] = 1'b1; else if (a[0]) y[1] = 1'b1; end endmodule
Attempts:
2 left
💡 Hint
Check which bits of input
a are set and which condition triggers first.✗ Incorrect
For input 3'b011, bit 2 is 0, bit 1 is 1, so only y[3] is set to 1. Only one output bit is high.
