0
0
Verilogprogramming~10 mins

If-else in always blocks in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start an always block triggered on the positive edge of clk.

Verilog
always @([1]) begin
  // code here
end
Drag options to blanks, or click blank then click option'
Anegedge clk
Bposedge clk
Cclk
Dposedge reset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'clk' without edge keyword causes continuous sensitivity.
Using 'negedge clk' triggers on falling edge, not rising.
2fill in blank
medium

Complete the if statement to check if reset is active high inside an always block.

Verilog
always @(posedge clk) begin
  if ([1]) begin
    // reset logic
  end
end
Drag options to blanks, or click blank then click option'
Areset == 0
Breset = 1
Creset != 1
Dreset == 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using single '=' instead of '==' causes syntax errors.
Checking for reset == 0 is active low, not active high.
3fill in blank
hard

Fix the error in the else statement syntax inside the always block.

Verilog
always @(posedge clk) begin
  if (reset == 1) begin
    q <= 0;
  end [1] begin
    q <= d;
  end
end
Drag options to blanks, or click blank then click option'
Aelse
Belsif
Celse if
Delseif
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'elsif' or 'elseif' causes syntax errors.
Writing 'else if' without condition is incorrect here.
4fill in blank
hard

Fill both blanks to complete a nested if-else inside an always block checking enable and reset.

Verilog
always @(posedge clk) begin
  if ([1]) begin
    if ([2]) begin
      q <= 0;
    end else begin
      q <= d;
    end
  end
end
Drag options to blanks, or click blank then click option'
Aenable
Breset == 1
Creset == 0
Denable == 0
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing reset active low with active high.
Using 'enable == 0' instead of 'enable'.
5fill in blank
hard

Fill all three blanks to complete a synchronous reset and load enable logic inside an always block.

Verilog
always @(posedge clk) begin
  if ([1]) begin
    q <= 0;
  end else if ([2]) begin
    q <= [3];
  end
end
Drag options to blanks, or click blank then click option'
Areset == 1
Bload == 1
Cd
Denable == 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enable' instead of 'load' for loading data.
Assigning 'enable == 1' to q instead of data signal.