Rule 110 is a one-dimensional cellular automaton with interesting properties (such as being Turing-complete).
There is a one-dimensional array of cells (on or off). At each time step, the state of each cell changes. In Rule 110, the next state of each cell depends only on itself and its two neighbours, according to the following table:
(The name “Rule 110” comes from reading the “next state” column: 01101110 is decimal 110.)
In this circuit, create a 512-cell system (q[511:0]), and advance by one time step each clock cycle. The load input indicates the state of the system should be loaded with data[511:0]. Assume the boundaries (q[-1] and q[512]) are both zero (off).
前言
三个输入,包括一个时钟clk,一个载入信号load,一个输入信号data;一个输出信号q。
代码
module top_module(
input clk,
input load,
input [511:0] data,
output [511:0] q
);
wire [511:0] l,r;
assign l=q<<1;
assign r=q>>1;
always@(posedge clk)begin
if(load) q<=data;
else begin
q<=(q^l)|((~r)&q);
end
end
endmodule
总结
这道题有个bug,借助Logisim的组合逻辑分析,根据真值表得到的输出表达式为q<=(q^r)|((~l)&q),但网页仿真结果出错,猜测应该是真值表的 Left 和 Right 部分写反。