我正在用 GENERATE 设计一个 n 位 bitslice ALU,我写了这段代码:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
ENTITY ALU IS
GENERIC (n : integer := 8);
PORT (A,B : IN std_logic_vector(n-1 DOWNTO 0);
funct : IN std_logic_vector (2 DOWNTO 0);
clk,nrst : IN std_logic;
Z : OUT std_logic_vector (n-1 DOWNTO 0);
ov,cout : OUT std_logic);
END ALU;
ARCHITECTURE bitSlice OF ALU IS
SIGNAL C : std_logic_vector (0 TO n);
SIGNAL temp : std_logic_vector (n-1 DOWNTO 0);
BEGIN
L1:IF nrst = '1' GENERATE
L2:IF funct = "000" GENERATE Z <= A;
END GENERATE L2;
L3:IF funct = "001" GENERATE Z <= B;
END GENERATE L3;
L4:IF funct = "010" GENERATE
c(0) <= '0';
cout <= C(n);
ov <= C(n);
L5: FOR i IN 0 TO n-1 GENERATE
Z(i) <= (A(i) XOR B(i) XOR C(i));
C(i+1) <= (A(i) AND B(i)) OR
(A(i) AND C(i)) OR
(B(i) AND C(i));
END GENERATE L5;
END GENERATE L4;
L6:IF funct = "011" GENERATE
c(0) <= '0';
cout <= C(n);
ov <= C(n);
temp <= std_logic_vector(signed(NOT(b))+1);
L7: FOR i IN 0 TO n-1 GENERATE
Z(i) <= (A(i) XOR temp(i) XOR C(i));
C(i+1) <= (A(i) AND temp(i)) OR
(A(i) AND C(i)) OR
(B(i) AND C(i));
END GENERATE L7;
END GENERATE L6;
L8:IF funct = "100" GENERATE Z <= A(n-1 DOWNTO 0) & '0';
END GENERATE L8;
L9:IF funct = "101" GENERATE Z <= B(n-1 DOWNTO 0) & '0';
END GENERATE L9;
L10:IF funct = "110" GENERATE Z <= '0' & a(n DOWNTO 1);
END GENERATE L10;
L11:IF funct = "111" GENERATE Z <= '0' & b(n DOWNTO 1);
END GENERATE L11;
END GENERATE L1;
END bitSlice;
它编译得很好,但它不起作用,尽管在生成块中有一堆警告说 IF 语句必须是静态的。我想知道我在哪里做错了。