function [63:0]step; input [63:0]field; reg [63:0]new_field; reg [7:0]position; reg [7:0]count; integer x; integer y; begin new_field = field; for(x = 0; x < 8; x = x + 1 ) begin: iloop for(y = 0; y < 8; y = y + 1) begin: jloop count = neighbour_count(field,x,y); position = to_1d(x,y); if (count == 3) new_field[position] = 1; else if ((count < 2) || (count > 3)) new_field[position] = 0; end end step = new_field; end endfunction function [7:0]neighbour_count; input [63:0]field; input [7:0]x; input [7:0]y; reg [7:0]count; reg [7:0]position; begin count = 0; position = to_1d(x-1,y-1); count = count + field[position]; position = to_1d(x,y-1); count = count + field[position]; position = to_1d(x + 1, y - 1); count = count + field[position]; position = to_1d(x - 1, y); count = count + field[position]; position = to_1d(x + 1, y); count = count + field[position]; position = to_1d(x - 1, y + 1); count = count + field[position]; position = to_1d(x, y + 1); count = count + field[position]; position = to_1d(x + 1, y + 1); count = count + field[position]; neighbour_count = count; end endfunction function [7:0]to_1d; input [7:0]x; input [7:0]y; begin if (x >= 8'b11111111) x = x + 8'd8; else if (x >= 8'd8) x = x - 8'd8; if (y >= 8'b11111111) y = y + 8'd8; else if (y >= 8'd8) y = y - 8'd8; to_1d = x + y * 8'd8; end endfunction
Source: https://habr.com/ru/post/429764/
All Articles