📖 Scenario: You are designing a simple digital circuit in VHDL that adds two 4-bit numbers. To ensure your design works correctly, you want to use assert statements to verify the output during simulation.
🎯 Goal: Build a VHDL testbench that uses assert statements to check if the sum output of your adder matches the expected result for given inputs.
📋 What You'll Learn
Create signals for inputs and output
Add a configuration signal for test values
Write an assert statement to verify the output
Print a message when the assertion fails
💡 Why This Matters
🌍 Real World
Using assert statements helps catch errors early in digital circuit design by verifying expected behavior during simulation.
💼 Career
Verification engineers and digital designers use assert statements to ensure their hardware designs work correctly before manufacturing.
Progress0 / 4 steps
1
DATA SETUP: Declare input and output signals
Declare signals a and b as 4-bit std_logic_vector inputs, and sum as a 5-bit std_logic_vector output in your VHDL testbench.
VHDL
Hint
Use signal keyword and specify the bit ranges exactly as shown.
2
CONFIGURATION: Assign test values to inputs
Assign the value "0011" to signal a and "0101" to signal b in your testbench process.
VHDL
Hint
Use signal assignment with <= and double quotes for bit vectors.
3
CORE LOGIC: Write an assert statement to verify the sum
Write an assert statement that checks if sum equals "01000". If not, display the message "Sum is incorrect" with severity error.
VHDL
Hint
Use assert condition report message severity level; syntax.
4
OUTPUT: Display the assertion result
Add a report statement to print "Test completed" after the assert statement.
VHDL
Hint
Use report "message"; to print messages in VHDL.
Practice
(1/5)
1. What is the main purpose of the assert statement in VHDL?
easy
A. To check conditions during simulation and report errors
B. To declare variables in the design
C. To assign values to signals
D. To create loops in the code
Solution
Step 1: Understand the role of assert in VHDL
The assert statement is used to verify conditions during simulation, helping catch errors early.
Step 2: Compare with other options
Other options describe unrelated tasks: declaring variables, assigning signals, or looping.
Final Answer:
To check conditions during simulation and report errors -> Option A
Quick Check:
Assert checks conditions = To check conditions during simulation and report errors [OK]
Hint: Assert is for checking conditions during simulation [OK]
Common Mistakes:
Confusing assert with signal assignment
Thinking assert declares variables
Assuming assert creates loops
2. Which of the following is the correct syntax for an assert statement in VHDL?
easy
A. assert condition, "message", severity level;
B. assert (condition) then report "message" severity level;
C. assert condition report "message" severity level;
D. assert condition report "message" severity level
Solution
Step 1: Recall correct assert syntax
The correct syntax is: assert condition report "message" severity level; with a semicolon at the end.
Hint: False assert with warning shows message but continues [OK]
Common Mistakes:
Thinking simulation stops on warning severity
Ignoring the severity level
Assuming no message if condition false
4. Identify the error in this VHDL assert statement:
assert (a = b) report "Mismatch" severity error
medium
A. Missing semicolon at the end
B. Incorrect use of parentheses around condition
C. Wrong severity level keyword
D. Missing report keyword
Solution
Step 1: Check syntax completeness
The assert statement must end with a semicolon; it is missing here.
Step 2: Verify other parts
Parentheses around condition are allowed, severity keyword is correct, and report keyword is present.
Final Answer:
Missing semicolon at the end -> Option A
Quick Check:
Assert statements end with semicolon [OK]
Hint: Always end assert statements with semicolon [OK]
Common Mistakes:
Forgetting semicolon
Thinking parentheses are not allowed
Confusing severity keywords
5. You want to verify that a signal data_valid is always true during simulation. Which assert statement correctly stops simulation on failure and shows an error message?
hard
A. assert data_valid report "Data invalid" severity critical;
B. assert data_valid report "Data invalid" severity warning;
C. assert not data_valid report "Data invalid" severity note;
D. assert data_valid report "Data invalid" severity error;
Solution
Step 1: Understand severity levels for stopping simulation
Severity error stops simulation and reports an error message.
Step 2: Analyze each option
assert data_valid report "Data invalid" severity warning; uses warning (does not stop). assert data_valid report "Data invalid" severity error; uses error (correct). assert not data_valid report "Data invalid" severity note; negates condition and uses note (no stop). assert data_valid report "Data invalid" severity critical; uses critical which is not a valid severity.
Final Answer:
assert data_valid report "Data invalid" severity error; -> Option D