gpt4 book ai didi

Always block 中的 Verilog 递归

转载 作者:行者123 更新时间:2023-12-02 05:21:14 25 4
gpt4 key购买 nike

我有一个希望使用递归的 verilog 代码。但是,每当我在 always block 中尝试这个时,它都会给出一个错误,说这不是一项任务。

有什么方法可以在 always block 中实现模块?还有我可以在 always block 中使用递归吗?

最佳答案

您可以使用生成 block 编写递归模块:

module unary_and
#(parameter WIDTH = 32)
(input [WIDTH-1:0] in_and,
output out_and)

generate
if(WIDTH == 1) begin
assign out_and = in_and;
end
else if(WIDTH == 2) begin
assign out_and = in_and[0] & in_and[1];
end
else begin
unary_and #(.WIDTH (WIDTH/2))
unary_and_low
(.in_and (in_and[WIDTH/2-1:0]),
.out_and (out_and_low));

unary_and #(.WIDTH (WIDTH - WIDTH/2))
unary_and_high
(.in_and (in_and[WIDTH-1:WIDTH/2]),
.out_and (out_and_high));

assign out_and = out_and_low & out_and_high;
end
endgenerate
endmodule

这是来自 Recursive and Iterative designs in Verilog您还可以在哪里找到其他解决方案。你可以看看Recursive Modules也是。

也许你还应该看看这些问题和答案:
Could we have generate inside an always block?
Verilog generate/genvar in an always block

关于Always block 中的 Verilog 递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13813397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com