我正在尝试为小型 CPU 设计制作一个缓冲区来保存 16 条 16 位宽的指令。
我需要一种方法将指令从我的测试平台加载到缓冲区中。所以我想使用 std_logic_vectors 数组来完成这个。但是,我遇到了语法错误,我不确定为什么(或者是否允许我在 VHDL 中这样做)。
语法错误在我声明 instructions
的那一行
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity instruction_buffer is
port
(
reset : in std_logic;
instructions : in array(0 to 15) of std_logic_vector(15 downto 0);
instruction_address : in std_logic_vector(3 downto 0);
clk : in std_logic;
instruction_out : out std_logic_vector(15 downto 0)
);
end instruction_buffer;
我也试过这样做,但后来我的实体端口映射中出现语法错误,告诉我
std_logic_vector
是未知类型。我发誓,VHDL 的语法错误没有 C 有意义 哈哈library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
package instructionBuffer is
type instructionBuffer is array(0 to 15) of std_logic_vector (15 downto 0);
end package instructionBuffer;
entity instruction_buffer is
port
(
instruction_address : in std_logic_vector(3 downto 0);
clk : in std_logic;
instruction_out : out std_logic_vector(15 downto 0)
);
end instruction_buffer;
最佳答案
无需拆分成两个文件,只需将所有代码放在一个文件中即可。您还可以在包中使用泛型来实现可扩展性:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
package instruction_buffer_type is
constant INSTRUCTION_BUFFER_ADDRESS : integer := 4; --bits wide
constant INSTRUCTION_BUFFER_DATA : integer := 16; --bits wide
type instructionBuffer is array(0 to 2**INSTRUCTION_BUFFER_ADDRESS -1) of std_logic_vector (INSTRUCTION_BUFFER_DATA -1 downto 0);
end package instruction_buffer_type;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.instruction_buffer_type.all;
entity instruction_buffer is
port
(
instruction_address : in std_logic_vector(INSTRUCTION_BUFFER_ADDRESS-1 downto 0);
instructions : in instructionBuffer;
clk : in std_logic;
instruction_out : out std_logic_vector(INSTRUCTION_BUFFER_DATA-1 downto 0)
);
end instruction_buffer;
关于syntax-error - 在 VHDL 中的实体内声明数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20308514/