Challenge - 5 Problems
Verilog Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this Verilog array declaration?
Consider the following Verilog code snippet. What is the width and number of elements of the declared array?
Verilog
reg [7:0] my_array [0:3];
Attempts:
2 left
💡 Hint
Look at the range in the declaration and the bit width inside the brackets.
✗ Incorrect
The declaration reg [7:0] my_array [0:3]; creates an array with indices from 0 to 3, so 4 elements total. Each element is 8 bits wide (from 7 down to 0).
❓ Predict Output
intermediateWhat is the size of this multidimensional array?
Given this Verilog declaration, how many total bits does the array occupy?
Verilog
reg [3:0] matrix [0:1][0:2];
Attempts:
2 left
💡 Hint
Multiply the number of elements in each dimension by the bit width.
✗ Incorrect
The array has 2 elements in the first dimension (0 to 1) and 3 in the second (0 to 2), total 6 elements. Each element is 4 bits wide, so 6 * 4 = 24 bits total.
🔧 Debug
advancedIdentify the error in this array declaration
What error will this Verilog code produce?
Verilog
reg [7:0] data_array [7];
Attempts:
2 left
💡 Hint
Array indices must specify a range, not a single number.
✗ Incorrect
In Verilog, array declarations require a range for indices like [0:7], not a single number [7]. Using [7] alone is a syntax error.
❓ Predict Output
advancedWhat is the value of element after assignment?
Given this Verilog code, what is the value of my_array[2] after execution?
Verilog
reg [3:0] my_array [0:3]; initial begin my_array[2] = 4'b1010; end
Attempts:
2 left
💡 Hint
Look at the assignment statement carefully.
✗ Incorrect
The code assigns the binary value 1010 to my_array[2], so its value is 4'b1010.
🧠 Conceptual
expertHow does Verilog store packed vs unpacked arrays?
Which statement correctly describes the difference between packed and unpacked arrays in Verilog?
Attempts:
2 left
💡 Hint
Think about how bits are arranged and accessed in memory.
✗ Incorrect
Packed arrays are stored as contiguous bits and support slicing like vectors. Unpacked arrays are arrays of separate variables and do not support slicing.
