Bird
Raised Fist0
Verilogprogramming~20 mins

Register (multi-bit flip-flop) in Verilog - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Register Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a 4-bit register with synchronous reset
What is the output q of this 4-bit register after the rising edge of the clock if reset is high?

Assume initial q = 4'b1010 and d = 4'b1100.
Verilog
module reg4bit(input clk, input reset, input [3:0] d, output reg [3:0] q);
  always @(posedge clk) begin
    if (reset)
      q <= 4'b0000;
    else
      q <= d;
  end
endmodule
Aq = 4'b0000
Bq = 4'b1010
Cq = 4'b1100
Dq = 4'b1111
Attempts:
2 left
💡 Hint
Remember that synchronous reset sets the output to zero on clock edge when reset is high.
❓ Predict Output
intermediate
2:00remaining
Value of a 3-bit register after multiple clock cycles
Given this 3-bit register with asynchronous reset, what is the value of q after the second rising edge of clk?

Initial q = 3'b011, d = 3'b101, and reset is low during both clock edges.
Verilog
module reg3bit(input clk, input reset, input [2:0] d, output reg [2:0] q);
  always @(posedge clk or posedge reset) begin
    if (reset)
      q <= 3'b000;
    else
      q <= d;
  end
endmodule
Aq = 3'b111
Bq = 3'b011
Cq = 3'b000
Dq = 3'b101
Attempts:
2 left
💡 Hint
Asynchronous reset is not active, so register loads d on clock edges.
🔧 Debug
advanced
2:00remaining
Identify the error in this 8-bit register code
This 8-bit register code is intended to load data d on the rising edge of clk. What error will occur when compiling or simulating this code?
Verilog
module reg8bit(input clk, input [7:0] d, output reg [7:0] q);
  always @(posedge clk) begin
    q <= d;
  end
endmodule
ANo error; code works as intended
BSynthesis warning: use non-blocking assignment '<=' inside always block for registers
CSyntax error: missing semicolon after 'q = d'
DRuntime error: q never updates
Attempts:
2 left
💡 Hint
Consider the difference between blocking '=' and non-blocking '<=' assignments in sequential logic.
📝 Syntax
advanced
2:00remaining
Syntax error in multi-bit register declaration
Which option contains the correct syntax to declare a 16-bit register named reg_data?
Areg [0:15] reg_data;
Breg [15:0] reg_data;
Creg reg_data : 16;
Dreg reg_data[15:0];
Attempts:
2 left
💡 Hint
In Verilog, the bit range is declared inside square brackets before the variable name.
🚀 Application
expert
2:00remaining
Number of bits flipped in a 5-bit register after input change
A 5-bit register q initially holds 5'b10101. On the next clock edge, it loads d = 5'b11011. How many bits in q will flip (change value) after the clock edge?
A4
B2
C3
D1
Attempts:
2 left
💡 Hint
Compare each bit of the initial and new values to count differences.

Practice

(1/5)
1.

What is the main purpose of a multi-bit register in Verilog?

easy
A. To store multiple bits of data and update them on clock edges
B. To perform arithmetic operations on data
C. To generate clock signals
D. To convert analog signals to digital

Solution

  1. Step 1: Understand the function of a register

    A register is used to hold data bits temporarily in digital circuits.
  2. Step 2: Recognize clock edge behavior

    Registers update their stored data only on clock edges, making them synchronous storage elements.
  3. Final Answer:

    To store multiple bits of data and update them on clock edges -> Option A
  4. Quick Check:

    Register = multi-bit storage updated on clock edges [OK]
Hint: Registers store bits and update only on clock edges [OK]
Common Mistakes:
  • Confusing registers with combinational logic
  • Thinking registers generate clocks
  • Assuming registers perform arithmetic
2.

Which of the following is the correct way to declare an 8-bit register in Verilog?

?
easy
A. reg [7:0] my_reg;
B. reg my_reg[7:0];
C. register [8] my_reg;
D. reg my_reg : 8;

Solution

  1. Step 1: Recall Verilog register declaration syntax

    Registers are declared with 'reg' keyword followed by bit range in square brackets before the name.
  2. Step 2: Check each option

    reg [7:0] my_reg; uses correct syntax: 'reg [7:0] my_reg;'. Others have syntax errors or wrong keywords.
  3. Final Answer:

    reg [7:0] my_reg; -> Option A
  4. Quick Check:

    Correct reg declaration = reg [7:0] name; [OK]
Hint: Use reg [MSB:LSB] name; to declare multi-bit registers [OK]
Common Mistakes:
  • Placing bit range after variable name
  • Using 'register' keyword instead of 'reg'
  • Using colon instead of square brackets
3.

Given the following Verilog code, what will be the value of reg_out after the positive edge of clk if reset is 0 and data_in is 8'b10101010?

module reg_example(input clk, input reset, input [7:0] data_in, output reg [7:0] reg_out);
  always @(posedge clk or posedge reset) begin
    if (reset)
      reg_out <= 8'b00000000;
    else
      reg_out <= data_in;
  end
endmodule
medium
A. 8'b00000000
B. 8'b10101010
C. 8'b11111111
D. No change in reg_out

Solution

  1. Step 1: Analyze the always block sensitivity

    The block triggers on positive edge of clk or reset. If reset is high, reg_out resets to zero.
  2. Step 2: Check conditions given

    Reset is 0, so reg_out will be assigned data_in value on clk rising edge, which is 8'b10101010.
  3. Final Answer:

    8'b10101010 -> Option B
  4. Quick Check:

    Reset=0, reg_out = data_in = 10101010 [OK]
Hint: If reset=0, reg_out updates to data_in on clk edge [OK]
Common Mistakes:
  • Assuming reset clears reg_out when reset=0
  • Ignoring clock edge sensitivity
  • Confusing blocking and non-blocking assignments
4.

Identify the error in this Verilog register code snippet:

always @(posedge clk) begin
  if (reset == 1)
    reg_data = 8'b0;
  else
    reg_data <= input_data;
end
medium
A. Incorrect bit width for reg_data
B. Missing sensitivity to reset signal
C. Using blocking assignment (=) for reset instead of non-blocking (<=)
D. Using '==' instead of '=' in if condition

Solution

  1. Step 1: Review assignment types in sequential blocks

    Inside always @(posedge clk), non-blocking assignments (<=) should be used for registers to avoid race conditions.
  2. Step 2: Identify the error in reset assignment

    The reset assignment uses blocking '=' which is incorrect; it should be '<=' to match the else branch.
  3. Final Answer:

    Using blocking assignment (=) for reset instead of non-blocking (<=) -> Option C
  4. Quick Check:

    Use <= for all register assignments in clocked always blocks [OK]
Hint: Use <= for all assignments inside clocked always blocks [OK]
Common Mistakes:
  • Mixing blocking and non-blocking assignments
  • Not including reset in sensitivity list (not error here but common)
  • Using '==' in if condition is correct syntax
5.

You want to create a parameterized multi-bit register module with asynchronous reset that can hold WIDTH bits. Which of the following code snippets correctly implements this?

module param_reg #(parameter WIDTH = 8) (
  input clk,
  input reset,
  input [WIDTH-1:0] data_in,
  output reg [WIDTH-1:0] data_out
);
  always @(posedge clk or posedge reset) begin
    if (reset)
      data_out <= {WIDTH{1'b0}};
    else
      data_out <= data_in;
  end
endmodule
hard
A. Incorrect: data_out declared as wire instead of reg
B. Incorrect: missing parameter declaration
C. Incorrect: synchronous reset used instead of asynchronous
D. Correct parameterized register with asynchronous reset

Solution

  1. Step 1: Check parameter usage

    The module declares parameter WIDTH and uses it to size inputs and outputs correctly.
  2. Step 2: Verify asynchronous reset and assignments

    The always block triggers on posedge clk or reset, and reset asynchronously clears data_out using replication operator.
  3. Step 3: Confirm data_out declared as reg

    data_out is declared as reg, which is required for assignment inside always block.
  4. Final Answer:

    Correct parameterized register with asynchronous reset -> Option D
  5. Quick Check:

    Parameter + async reset + reg output = correct [OK]
Hint: Use parameter and replication operator for flexible reset [OK]
Common Mistakes:
  • Forgetting parameter declaration
  • Using synchronous reset when async needed
  • Declaring output as wire instead of reg
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard