我目前正試圖編譯一個使用兩個while循環的移位器。 For-loops,shift功能和日誌功能是不可能的。但是,當我嘗試編譯它時,它會在指定的行處拋出「具有非恆定循環條件的循環」錯誤。該線的邊際條件是i < j,其中j是N-1,N是參數。我的問題是,由於N是一個參數,爲什麼即使在編譯時它也不是常量,因此被認爲是一個恆定的循環條件?While循環與非恆定循環條件,但使用參數
下面是代碼:
module shifter(input logic [0:0] SW0, SW1, SW2, SW3, SW4, SW5, SW6, SW7, SW8, SW9, SW10,
input logic [0:0] KEY0, KEY1,
output logic [0:0] LEDG0, LEDG1, LEDG2, LEDG3, LEDG4, LEDG5, LEDG6, LEDG7);
parameter N=8;
//receive input from switches
logic [7:0] bits = '0;
logic [7:0] out = '0;
logic [0:0] move = '0;
logic [2:0] shift = '0;
logic next = 1;
always_comb
begin
bits[7] = SW7[0];
bits[6] = SW6[0];
bits[5] = SW5[0];
bits[4] = SW4[0];
bits[3] = SW3[0];
bits[2] = SW2[0];
bits[1] = SW1[0];
bits[0] = SW0[0];
shift[2] = SW10[0];
shift[1] = SW9[0];
shift[0] = SW8[0];
end
logic i = 0;
logic k = 0;
logic [31:0] j = N - 1;
[email protected](negedge KEY0)
begin
k <= shift[2:0];
do
begin
move <= bits[0];
do
begin
bits[i] <= bits[next];
i <= i + 1;
next <= i + 1;
end
while (i < j); //<-------indicated line
bits[7] <= move;
k <= k - 1;
end
while(k > 0);
out <= bits;
end
always_comb
begin
LEDG0 = out[0];
LEDG1 = out[1];
LEDG2 = out[2];
LEDG3 = out[3];
LEDG4 = out[4];
LEDG5 = out[5];
LEDG6 = out[6];
LEDG7 = out[7];
end
endmodule
嘗試'我<(N-1)'而不是'我
noobuntu
@noobuntu我試過了,它拋出了另一個錯誤,說「循環必須在5000次迭代內終止」 – user7231602
這通常是用for-循環。爲什麼認爲這是不可能的? – toolic