Another Behavioral Example
module life (neighbors, self, out); input self; input [7:0] neighbors; output out; reg out; integer count; integer i; always @(neighbors or self) begin count = 0; for (i = 0; iɠ i = i+1) count = count + neighbors[i]; out = 0; out = out | (count == 3); out = out | ((self == 1) & (count == 2)); endendmodule
always block is executed instantaneously, if there are no delays only the final result is used
integers are temporary compiler variables
Combinational block that computes Conway’s Game of Life rule