Challenge - 5 Problems
Verilog Synthesizable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a synthesizable always block
What is the output value of
Assume
out after the following Verilog code runs for one clock cycle?Assume
clk is a clock signal and rst is an active-high reset.Verilog
module test(input clk, input rst, input [3:0] in, output reg [3:0] out); always @(posedge clk or posedge rst) begin if (rst) out <= 4'b0000; else out <= in + 1; end endmodule
Attempts:
2 left
💡 Hint
Think about how the always block triggers on the positive edge of clk or rst.
✗ Incorrect
The always block triggers on the positive edge of clk or rst. If rst is high, out resets to 0. Otherwise, on the clock edge, out updates to in + 1. This is synthesizable sequential logic.
❓ Predict Output
intermediateOutput of a non-synthesizable initial block
What happens when the following Verilog code is simulated?
Is this code synthesizable?
Is this code synthesizable?
Verilog
module test; reg [3:0] count; initial begin count = 4'b1010; #10 count = 4'b0101; end endmodule
Attempts:
2 left
💡 Hint
Consider what initial blocks and delays (#) mean in synthesis.
✗ Incorrect
Initial blocks and delays (#) are used for simulation only and are not synthesizable. The code initializes count at time 0 and changes it after 10 time units during simulation.
🔧 Debug
advancedIdentify the non-synthesizable construct
Which line in the following Verilog code is non-synthesizable and why?
Verilog
module test(input clk, input rst, output reg [3:0] out); integer i; always @(posedge clk) begin for (i = 0; i < 4; i = i + 1) begin out[i] <= ~out[i]; end end endmodule
Attempts:
2 left
💡 Hint
Think about variable types allowed in synthesizable loops.
✗ Incorrect
Using an integer variable for loop control in synthesizable code is not allowed because synthesis tools require loop variables to be constant or parameters. The for loop and bitwise negation are synthesizable, as is non-blocking assignment.
📝 Syntax
advancedWhich code snippet is synthesizable?
Which of the following Verilog code snippets is synthesizable and will not cause synthesis errors?
Attempts:
2 left
💡 Hint
Consider blocking vs non-blocking assignments and delay usage in synthesis.
✗ Incorrect
Option B uses non-blocking assignment (<=) inside a clocked always block, which is synthesizable. Option B uses blocking assignment (=) which can cause issues in sequential logic. Options B and D use delays (#), which are not synthesizable.
🚀 Application
expertDetermine the number of items in a synthesizable array
Given the following Verilog code, how many elements does the synthesizable array
mem contain after synthesis?Verilog
module test(input clk, input [3:0] addr, input [7:0] data_in, output reg [7:0] data_out); reg [7:0] mem [0:15]; always @(posedge clk) begin mem[addr] <= data_in; data_out <= mem[addr]; end endmodule
Attempts:
2 left
💡 Hint
Look at the array declaration range.
✗ Incorrect
The array mem is declared from index 0 to 15, which means it contains 16 elements. This is synthesizable as a memory block.
