Home › Practice › Formal Verification › Your first assertion: the bigger of two
Your first assertion: the bigger of two
EasyFormalassertcombinational
Testing tries a few inputs and hopes. Formal checking asks a tool to try all of them. For that the tool needs a rule it can check. That rule is an assertion. You will write one.
Concept first. An assertion is a statement that must be true every time you look. Example with other numbers: a design adds 1 to a number and gives back y. A good assertion is assert(y != x): whatever x is, the answer must differ from it. The tool then hunts for a single input that breaks the rule. If it finds none, the rule holds for every input. If it finds one, it shows you that input.
The design below returns the larger of two 4-bit numbers. You do not write it. You write a checker: a small module that watches a, b and y and asserts what must always be true. The grader runs your checker on this correct design (it must hold) and on three broken versions (it must catch every one).
module dut(input [3:0] a, input [3:0] b, output [3:0] y);
assign y = (a > b) ? a : b;
endmodule
- Keep the module name
chkand its ports. - Write your assertions inside the
always @*block. Theifdef FORMALlines mean "only the formal tool reads this", the same trick real projects use. - State what is true of the answer, not how to compute it. A checker that repeats the design always agrees with it, so it can never find a bug.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.