如何从VHDL中的rom_type读取数据?

发布于 2024-08-12 20:10:13 字数 360 浏览 2 评论 0原文

如何从 rom_type 读取数据?

entity my_rom is
 port(
  addr: in std_logic_vector(3 downto 0);
  data: out std_logic_vector(0 to 7)
 );
end my_rom;
architecture a of my_rom is

 type rom_type is array (0 to 7) of std_logic_vector(0 to 7);
 constant R1_ROM: rom_type :=
 (
  -- data
 );
begin
 data <= R1_rom(conv_integer(addr));
end a;

How can I read data from rom_type?

entity my_rom is
 port(
  addr: in std_logic_vector(3 downto 0);
  data: out std_logic_vector(0 to 7)
 );
end my_rom;
architecture a of my_rom is

 type rom_type is array (0 to 7) of std_logic_vector(0 to 7);
 constant R1_ROM: rom_type :=
 (
  -- data
 );
begin
 data <= R1_rom(conv_integer(addr));
end a;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-08-19 20:10:13

您正在使用 conv_integer,它不是原始 VHDL 的一部分......它位于库中。但是,您不想使用它 - 它来自非标准库

相反, use ieee.numeric_std.all; 是您在实体之前需要的。然后使用 to_integer(unsigned(addr)) 来索引 ROM。更好的是,将地址作为无符号向量传递,甚至直接作为整数传递。

尝试摆脱使用 std_logic_vector(只是一包位)来表示数字的习惯,并使用定义明确的数字类型。

或者使用 Verilog,它并不关心:)

我自己,我更喜欢 VHDL 的强类型,以防止我愚蠢的脚步射击......

You are using conv_integer, which is not part of raw VHDL... it's in a library. However, you don't want to use it - it's from a non-standard library.

Instead use ieee.numeric_std.all; is what you need before your entity. Then use to_integer(unsigned(addr)) to index the ROM. Better still, pass the address in as an unsigned vector, or even directly as an integer.

Try to get out of the habit of using std_logic_vector (which is just a bag of bits) to represent numbers, and use the well-defined numerical types.

Or use Verilog, which doesn't care :)

Myself, I prefer VHDL's strong-typing to keep me from daft foot-shooting...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文