前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDLbits Conwaylife

HDLbits Conwaylife

原创
作者头像
Player
发布2022-07-24 14:18:17
2400
发布2022-07-24 14:18:17
举报
文章被收录于专栏:Xilinx

这道题好像没有什么巧妙的办法,只有用for循环

代码语言:javascript
复制
module top_module(
    input clk,
    input load,
    input [255:0] data,
    output [255:0] q ); 
    
    integer i,j;
    integer m,n;
    integer x,y;

    // 18 * 18
    reg [304:-19] bq;

    // 16 * 16 -> 18 * 18
    always@(*) begin
        for(i = -1; i < 17; i += 1) begin
            for(j = -1; j < 17; j += 1) begin
                if(i == -1)m = 15;
                else if(i == 16)m = 0;
                else m = i;

                if(j == -1)n = 15;
                else if(j == 16)n = 0;
                else n = j;
                
                bq[i*18 + j] = q[m*16 + n];
            end
        end
    end
    
    reg [2:0] sum;
    always@(posedge clk) begin
        if(load)q <= data;
        else begin
            for(x = 0; x < 16; x += 1) begin
                for(y = 0; y < 16; y += 1) begin
                    sum = bq[x*18 + y + 1] + bq[x*18 + y - 1]
                    + bq[(x+1)*18 + y] + bq[(x+1)*18 + y + 1] + bq[(x+1)*18 + y - 1]
                    + bq[(x-1)*18 + y] + bq[(x-1)*18 + y + 1] + bq[(x-1)*18 + y - 1];
                    case(sum)
                        3'b010: q[x*16 + y] <= q[x*16 + y];
                        3'b011: q[x*16 + y] <= 1'b1;
                        default: q[x*16 + y] <= 1'b0;
                    endcase                    
                end
            end
        end
    end    

endmodule

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档