What you practice
always_ff (1.6). Model clocked sequential registers with always_ff, asynchronous reset, and non-blocking assignments. It is in Processes — Part 1 · Design in SV of the SystemVerilog Masterclass. Synthesizable SystemVerilog that removes Verilog ambiguity and cuts boilerplate.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
Today you will model clocked sequential registers using the always_ff block in SystemVerilog, enforcing single-clock edge sensitivity and non-blocking assignments for reliable hardware behavior.
Learning objectives
- Understand the purpose of
always_fffor synchronous sequential logic. - Write correct sensitivity lists with
posedge clkandnegedge rst_n. - Use non-blocking assignment (
<=) insidealways_ffblocks. - Distinguish asynchronous reset behavior from synchronous logic.
Theory
always_ff is a SystemVerilog block specifically for modeling flip-flops and sequential registers. It enforces synthesis tools to infer registers and prevents combinational inference mistakes. Key rules:
- Sensitivity list must include only one clock edge (e.g.,
posedge clk) plus optional asynchronous reset edge. - Use non-blocking assignment (
<=) to avoid race conditions in simulation and synthesis. - Asynchronous reset (
negedge rst_n) triggers immediately, independent of clock.
| Keyword | Purpose |
|---|---|
always_ff | Clocked sequential logic (registers) |
posedge | Positive clock edge trigger |
negedge | Negative edge trigger (e.g., active-low reset) |
<= | Non-blocking assignment (sequential) |
Practice
- Open RtlStudio and select this chapter — files appear automatically in Explore.
- Open
student/rtl/design.svin the editor. - Replace the
__TODO__placeholders to complete thealways_ffblock: write the sensitivity list andbegin/endblock header. - Run Simulation from the left sidebar and check the Log panel for
INFO:messages. - (Optional) Open the Waveform tab to inspect signal transitions aligned with stimulus steps.
Summary
You practiced modeling sequential logic using the always_ff block with explicit clock edge sensitivity and non-blocking assignments. You implemented a register with asynchronous or synchronous reset, reinforcing disciplined timing behavior. The key takeaway is that always_ff enforces synthesizable, single-clock sequential constructs essential for reliable hardware design. Always ensure reset polarity and assignment style match your intended hardware semantics.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches always_ff. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.