verilog HDLBits刷题[More Circuits]“Rule90”---Rule90
2026/7/26 4:58:07 网站建设 项目流程

1、题目

Rule 90 is a one-dimensional cellular automaton with interesting properties.

The rules are simple. There is a one-dimensional array of cells (on or off). At each time step, the next state of each cell is the XOR of the cell's two current neighbours. A more verbose way of expressing this rule is the following table, where a cell's next state is a function of itself and its two neighbours:

LeftCenterRightCenter's next state
1110
1101
1010
1001
0111
0100
0011
0000

(The name "Rule 90" comes from reading the "next state" column: 01011010 is decimal 90.)


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).

2、分析

load有效时,将data加载给q,无效时,进行Rule 90的算法。下一个状态的q等于当前状态的q相邻值的异或值。而q[-1] =q[512]=0.

3、代码

module top_module( input clk, input load, input [511:0] data, output reg[511:0] q ); reg [511:0]next_q; always@(*)begin next_q[0]=1'b0^q[1]; next_q[511]=1'b0^q[510]; for(int i=1;i<=510;i++)begin next_q[i]=q[i-1]^q[i+1]; end end always@(posedge clk)begin if(load) q<=data; else q<=next_q; end endmodule

4、结果

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询