verilog实例化多个寄存器



我写了一个8位寄存器模块,如下所示:

module ff_8 #(
     parameter q0=0
)(
    input clk,
    input rst_n,
    input enable,
    input [7:0] d,
    output reg[7:0] q,
    );
always @ (posedge clk)
if (!rst_n) begin
    q <= q0;
end else if(enable) begin
    q <= d;
end
endmodule

我如何在不必写128次相同代码的情况下,拥有多个(128)ff_8实例,每个实例都具有不同的q0参数?

在SystemVerilog中,您可以使用以下命令为整个寄存器阵列创建一个模块:

module flop_array #(
    parameter int unsigned depth = 128,
    parameter int unsigned width = 8,
    parameter bit [width-1:0] q0[depth] = '{default:0}
)(
    input clk,
    input rst_n,
    input enable,
    input [width-1:0] d[depth],
    output logic [width-1:0] q[depth]
);
always_ff @(posedge clk)
if (!rst_n) begin
    q <= q0;
end else if(enable) begin
    q <= d;
end
endmodule

最新更新