Immediate Assertions, Action Blocks and Severity
Write immediate assert, assume and cover checks in procedures, choose their action blocks, and pick the right severity task.
You Will Be Able To
- Write an immediate
assertwith a label, a pass action and anelseaction. - Predict when an immediate assertion in combinational code fires on a value that never settles.
- Choose between immediate
assert,assumeandcoverfor a rule. - Pick
$info,$warning,$erroror$fatalfor a failure, and say whether the run goes on.
- Lesson
- A1.4
- Time
- 25 min
- Runs on
- Verilator
- Check
- 5 questions
A decoder check failed once in a regression, at 10 ns. The waveform showed a = 0 and b = 1 at 10 ns, a legal one-hot pair. The check was right, and so was the waveform. Inside that one time step, a fell before b rose, and the check ran in between.
A waveform shows only the last value of each time step. The check ran twice inside it, once on a value that lasted zero time.
An Immediate Assertion Is a Checked If
An immediate assertion is a statement inside a procedure: assert (expr) pass_action else fail_action;. It runs when the procedure reaches it, like an if. It reads the current values of its signals, not sampled ones, and it takes no time.
expr evaluates to | Result | Action that runs |
|---|---|---|
| 1 (or any nonzero value) | pass | the pass action |
| 0 | fail | the else action |
x or z | fail | the else action |
An unknown value is a failure, as in IEEE 1800-2023 16.3.
Give each assertion a label, such as one_hot: assert (...). Tools print the label in their messages, so a failure names its rule.
Glitches in Combinational Code
An always @(a or b) block runs every time a or b changes. When the two changes come from different steps of one time step, the block runs in between them. An immediate assertion inside it then checks a value that never settles.
a, waits with #0, then writes b. The check block wakes after each write.- Step
- Storage
- Property
- Report
- Data
- Control
- First write
The bench writes
a = 0, then waits with#0. Waiting lets other processes run in the same time step.Follow the calls, values and waits
- data a = 0: Bench process → a and b
- The check runs early
The change on
awakes the check block. It readsa = 0andb = 0, soa ^ bis 0 and the fail action runs.Follow the calls, values and waits
- call a=0 b=0: a and b → Check block
- data one_hot failed: Check block → Log
- Second write
The bench resumes and writes
b = 1. The pair is now legal again.Follow the calls, values and waits
- data b = 1: Bench process → a and b
- The check runs again
The change on
bwakes the block a second time. Now it passes. The failure has already been printed.More context
When both writes come from one process with no wait between them, the block runs once, after both. How many times it runs in one time step depends on the scheduling, so such a check is fragile.
Follow the calls, values and waits
- call a=0 b=1: a and b → Check block
Read the diagram as text
- Bench process: a = 0; #0 b = 1;
- a and b: The variables
- Check block: always @(a or b)
- Log: Fail action output
- Bench process → a and b: writes
- a and b → Check block: wakes
- Check block → Log: fails
An immediate assertion checks the values of the moment it runs. In code that can run several times per time step, that moment may be in the middle.
There are two ways out. Check at a clock edge, where values are stable. Or use a deferred assertion, assert #0, which reports only the last result of the time step; a later lesson covers it.
Action Blocks
The pass action runs when the check passes, and the else action when it fails. Either can be one statement or a begin ... end block. Print the values you checked, so the message explains itself.
With no else, a failure calls $error with a message the tool chooses. Most checks leave the pass action out: a pass on every clock fills the log.
A message that says little
assert (a ^ b);
The tool prints its own text, without a or b.
A message that explains itself
one_hot: assert (a ^ b)
else $error("a=%b b=%b", a, b);
The label names the rule; the values show why.
Immediate Assume
assume (expr) states a rule about the inputs of the block under check, such as "the bench never drives mode 3". In simulation it is checked exactly like assert, and its else action runs on a failure.
A formal tool treats it differently. It does not check an assumption; it only explores inputs that obey it. So use assume for rules about the environment, and assert for rules the design must keep.
Immediate Cover
cover (expr) statement; runs its statement each time it is reached with expr true. It has no else, because nothing is wrong when a scenario does not happen. Tools also count it, so you can show that a scenario occurred.
Standard behaviour, not run on these simulators. The loop sets v to 0, 1, 2 and 3, then runs cover (v[0]) hits++;. By IEEE 1800-2023 16.3 the statement runs on each true evaluation, so hits ends at 2. Verilator 5.052 and Icarus 12 both end at 0 (measured 2026-11-12).
Until a tool runs the statement, count the scenario yourself. An if (expr) hits++; beside the cover gives the standard's number on both simulators.
$info: A Note in the Log
Four severity tasks report a message: $info, $warning, $error and $fatal. You can call them in action blocks or anywhere in procedural code. Each message also carries the time and the scope.
| Task | Means | Standard: the run | Icarus 12 | Verilator 5.052 |
|---|---|---|---|---|
$info | for your information | goes on | goes on | goes on |
$warning | suspicious, maybe fine | goes on | goes on | goes on |
$error | a rule was broken | goes on | goes on | stops ($stop) |
$fatal | nothing after this is meaningful | ends ($finish) | ends, final blocks run | stops ($stop), no final block |
The severity ladder. Only $fatal ends a run in the standard (IEEE 1800-2023 20.10). The two tool columns are measured.
$info is the lowest step. It records something worth knowing, such as a mode change, and the run goes on. Here it sits in a pass action.
$warning: Suspicious, and the Run Goes On
$warning reports something that may be wrong, such as a value close to a limit. The run goes on. Many flows count warnings and review them after the regression.
$error: A Broken Rule, and the Run Goes On
Use $error for a broken rule. In the standard the run goes on, so one run can report every failure. An assertion with no else calls $error too.
$fatal: The Run Ends
Use $fatal only when going on is pointless, such as a missing configuration file. It ends the run by calling $finish, so final blocks still run.
$fatal(n, "msg") passes n to $finish, which chooses how much to print on the way out. A 0 prints nothing extra. A 1 adds the time and place, and a 2 adds memory and CPU use. Icarus 12 prints the same for all three.
Try It
At 10, the #0 lets the check block run between the two writes, so one_hot fails on a=0 b=0. At 20, both writes come from one process with no wait, so the block sees only the legal result.
The assume fails at 30 like an assertion would. In a formal tool, it would instead stop the tool from ever trying mode 3. Delete the #0, so both writes at 10 come from one step, and predict the new count.
t=10 one_hot failed: a=0 b=0 t=30 mode_ok failed: mode=11 fails=1Check Yourself
Common Mistakes
Wrong Put an immediate assertion in an always @(*) block to check a combinational output.
The block can run several times in one time step, so the check can fire on a value that never settles.
Fix Check at a clock edge, or use a deferred assertion that reports the last result of the time step.
always @(*) begin
y = dec(sel);
assert ($onehot(y));
endalways @(posedge clk)
y_ok: assert ($onehot(y))
else $error("y=%b", y);Wrong End every failed check with $fatal to make failures impossible to miss.
The run stops at the first failure, so every later bug in the same run stays hidden.
Fix Use $error for broken rules, and keep $fatal for states where going on means nothing.
Wrong Count scenarios with the statement of an immediate cover on Verilator or Icarus.
Neither tool runs that statement, so the count stays at 0 while the scenario happens.
Fix Count with if (expr) hits++;, and read the cover from a tool that supports it.
Remember
- An immediate assertion runs when the procedure reaches it, on current values, and takes no time.
- An expression that is 0,
xorzfails; a known nonzero value passes. - In code that runs several times per time step, an immediate check can fire on a passing glitch.
assumeis checked likeassertin simulation; a formal tool obeys it instead.- Only
$fatalends the run in the standard;$error,$warningand$inforeport and go on.