We use reg type in Verilog to store values that can change inside a block of code. Procedural assignment lets us change these values step-by-step in a controlled way.
When you want to remember a value between steps in a process.
When you need to change a signal inside an <code>always</code> block.
When modeling simple memory or flip-flop behavior.
When you want to update a signal based on conditions or timing.
Syntax
Verilog
reg [width-1:0] name;
always @(sensitivity_list) begin
name = value; // procedural assignment
end
reg means the variable can hold a value over time.
2. Which of the following is the correct way to perform a blocking assignment to a reg inside an always block?
easy
A. reg_var = 1;
B. reg_var <= 1;
C. wire_var = 1;
D. reg_var := 1;
Solution
Step 1: Identify procedural assignment syntax
Inside always blocks, = is used for blocking assignments to reg.
Step 2: Check each option
reg_var = 1; is correct syntax for blocking; reg_var <= 1; is non-blocking; wire_var = 1; cannot assign to wire procedurally; reg_var := 1; is invalid in Verilog.
Final Answer:
reg_var = 1; -> Option A
Quick Check:
Procedural blocking assignment uses = for reg [OK]
Hint: Use = for blocking procedural reg assignments inside always [OK]
Common Mistakes:
Using := which is not Verilog syntax
Assigning to wire inside always
Confusing blocking (=) and non-blocking (<=) without context
3. What will be the value of count after the following code executes once?
reg [3:0] count;
always @ (posedge clk) begin
count = count + 1;
end
medium
A. count resets to 0
B. count remains unchanged
C. count increments by 1
D. Syntax error due to missing initial value
Solution
Step 1: Understand procedural increment
On each positive clock edge, count is assigned its current value plus 1.
Step 2: Consider initial value
If count was initialized or reset before, it increments by 1; no syntax error occurs without explicit initial value.
Final Answer:
count increments by 1 -> Option C
Quick Check:
Procedural assignment increments count [OK]
Hint: Procedural reg assignments update values on clock edges [OK]
Common Mistakes:
Assuming count resets automatically
Thinking missing initial value causes syntax error
Confusing reg with wire behavior
4. Identify the error in this Verilog snippet:
reg flag;
always @ (posedge clk) begin
flag = 1'b1;
end
assign flag = 1'b0;
medium
A. Missing semicolon after flag = 1'b1
B. Cannot assign flag both procedurally and continuously
C. Incorrect bit width for flag
D. No error, code is correct
Solution
Step 1: Check assignments to flag
flag is assigned inside an always block and also by a continuous assign.
Step 2: Understand Verilog rules
A reg cannot be driven by both procedural and continuous assignments simultaneously.
Final Answer:
Cannot assign flag both procedurally and continuously -> Option B
Quick Check:
Procedural and continuous assignments conflict [OK]
Hint: Avoid mixing procedural and continuous assignments on same reg [OK]
Common Mistakes:
Ignoring conflict between procedural and continuous assignments
Thinking missing semicolon causes error here
Confusing reg and wire assignment rules
5. Given the following code, what will be the final value of state after two positive clock edges?
reg [1:0] state = 2'b00;
always @ (posedge clk) begin
if (state == 2'b00)
state = 2'b01;
else
state = 2'b10;
end
hard
A. state toggles between 2'b01 and 2'b10 infinitely
B. state = 2'b01
C. state = 2'b00
D. state = 2'b10
Solution
Step 1: Trace first clock edge
Initial state is 2'b00, so after first clock edge it becomes 2'b01.
Step 2: Trace second clock edge
Now state is 2'b01, so after second clock edge it becomes 2'b10.
Final Answer:
state = 2'b10 -> Option D
Quick Check:
State updates stepwise on clock edges [OK]
Hint: Follow state changes step-by-step on each clock edge [OK]
Common Mistakes:
Assuming state stays at 2'b01 after two edges
Thinking state resets to 2'b00 automatically
Confusing procedural assignment timing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.