← ProblemsVerilog Language / Procedures

Always blocks (clocked)

64%proceduresflip-flops

A clocked always block — always @(posedge clk) — infers flip-flops: its outputs only update at the rising clock edge.

Build an XOR gate three ways:

  • out_assign: with an assign statement
  • out_always_comb: inside a combinational always @(*) block
  • out_always_ff: inside a clocked always @(posedge clk) block — this output is the XOR delayed by one clock edge, because it passes through a flip-flop

In the clocked block use a non-blocking assignment (<=); in the combinational block use a blocking assignment (=). Mixing them up causes subtle simulation bugs in larger designs.