0
0
Verilogprogramming~10 mins

Register (multi-bit flip-flop) in Verilog - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Register (multi-bit flip-flop)
Start
Wait for clock edge
On rising edge?
NoWait
Yes
Load input data into register
Hold data stable
Output register value
Repeat on next clock edge
This flow shows how a multi-bit register waits for a clock signal, then loads and holds data on each rising clock edge.
Execution Sample
Verilog
module register(clk, reset, d, q);
  input clk, reset;
  input [3:0] d;
  output reg [3:0] q;

  always @(posedge clk or posedge reset) begin
    if (reset) q <= 4'b0000;
    else q <= d;
  end
endmodule
This Verilog code defines a 4-bit register that loads input d into q on the rising clock edge or resets q to zero.
Execution Table
StepclkresetdConditionActionq (register output)
1014'b1010reset=1?Yes, q <= 00000000
21 (rising edge)04'b1010reset=0?Load d into q1010
3004'b1100No clock edgeHold q1010
41 (rising edge)04'b1100reset=0?Load d into q1100
5004'b1111No clock edgeHold q1100
61 (rising edge)04'b1111reset=0?Load d into q1111
71 (rising edge)14'b0001reset=1?Reset q to 00000000
💡 Simulation ends after reset is asserted again, register output reset to zero.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7
clk00101011
reset01000001
d00001010101011001100111111110001
q00000000101010101100110011110000
Key Moments - 3 Insights
Why does the register output q change only on the rising edge of clk?
Because the always block triggers only on posedge clk or posedge reset, so q updates only when clk rises or reset is active, as shown in steps 2, 4, 6, and 7.
What happens to q when reset is high, even if clk is not rising?
When reset is high, q is immediately set to zero regardless of clk, as seen in step 1 and step 7 in the execution_table.
Why does q hold its value when clk is low or no rising edge occurs?
Because the always block does not trigger without a rising edge on clk or reset, so q keeps its previous value, shown in steps 3 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of q after step 4?
A1100
B1010
C0000
D1111
💡 Hint
Check the 'q' column in row for step 4 in execution_table.
At which step does the reset signal cause q to become 0000?
AStep 4
BStep 1
CStep 2
DStep 6
💡 Hint
Look for steps where reset=1 and q is set to 0000 in execution_table.
If the reset signal stayed low, what would q be after step 7?
A0000
B1010
C1111
D1100
💡 Hint
Refer to variable_tracker for q values and consider reset effect at step 7.
Concept Snapshot
Register (multi-bit flip-flop) in Verilog:
- Use always @(posedge clk or posedge reset) block
- On reset=1, set q to zero
- On rising clk, load input d into q
- q holds value between clock edges
- Useful for storing multi-bit data synchronously
Full Transcript
This visual execution trace shows a 4-bit register in Verilog. The register waits for a rising clock edge or a reset signal. When reset is high, the register output q is set to zero immediately. On each rising clock edge, if reset is low, the input data d is loaded into q. Between clock edges, q holds its value stable. The execution table traces each step with clk, reset, d, and q values. The variable tracker shows how signals change over time. Key moments clarify why q updates only on clock edges or reset, and why it holds value otherwise. The quiz questions test understanding of q's value changes and reset behavior. This helps beginners see how a multi-bit flip-flop register works step-by-step.