0
0
Verilogprogramming~20 mins

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

Choose your learning style9 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.