How to use for loop statement in case statement in Verilog
我正在尝试编译类似这样的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | `define CORES_NUM 4 reg [1:0] core = 'h0; reg [`CORES_NUM-1:0] result = 'h0; integer i; always @ (posedge clk) begin case (core) for (i = 0; i < `CORES_NUM; i = i + 1) begin\t\t\t\t\t\t\t i: begin result[i] <= 1; end end endcase end |
目前只有一个核心处于活动状态。我希望我的代码等于:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | case (core)\t\t\t\t\t\t 0: begin result[0] <= 1; end 1: begin result[1] <= 1; end 2: begin result[2] <= 1; end 3: begin result[3] <= 1; end endcase |
换句话说,我只需要 \\'for loop\\' 来进行自动设置 - 如果我更改 CORES_NUM,则案例状态会自动更改。
但是我的代码构建时有错误。如何在 case 语句中使用 for 循环?
为什么不呢:
1 | always @(posedge clk) if (core < `CORES_NUM) result[core] = 1; |