Python:VHDL 代码生成器的代码

标签 python code-generation vhdl rom

我正在尝试用 VHDL 语言制作 ROM,我正在使用我在 http://www.edaboard.com/thread38052.html 上找到的模板:

library ieee;
use ieee.std_logic_1164.all;

entity ROM is
port ( address : in std_logic_vector(3 downto 0);
     data : out std_logic_vector(7 downto 0) );
end entity ROM;

architecture behavioral of ROM is
type mem is array ( 0 to 2**4 - 1) of std_logic_vector(7 downto 0);
constant my_Rom : mem := (
0  => "00000000",
1  => "00000001",
2  => "00000010",
3  => "00000011",
4  => "00000100",
5  => "11110000",
6  => "11110000",
7  => "11110000",
8  => "11110000",
9  => "11110000",
10 => "11110000",
11 => "11110000",
12 => "11110000",
13 => "11110000",
14 => "11110000",
15 => "11110000");
begin
process (address)
begin
 case address is
   when "0000" => data <= my_rom(0);
   when "0001" => data <= my_rom(1);
   when "0010" => data <= my_rom(2);
   when "0011" => data <= my_rom(3);
   when "0100" => data <= my_rom(4);
   when "0101" => data <= my_rom(5);
   when "0110" => data <= my_rom(6);
   when "0111" => data <= my_rom(7);
   when "1000" => data <= my_rom(8);
   when "1001" => data <= my_rom(9);
   when "1010" => data <= my_rom(10);
   when "1011" => data <= my_rom(11);
   when "1100" => data <= my_rom(12);
   when "1101" => data <= my_rom(13);
   when "1110" => data <= my_rom(14);
   when "1111" => data <= my_rom(15);
   when others => data <= "00000000";
 end case;
  end process;
  end architecture behavioral;

嗯,问题是我想输入我的 ROM 2000 值。所以我想知道如何使用 python 制作下一个:

假设您在 .txt 文件中有以下格式的数据:

0  45
1  56
2  78
3  98

因此程序将对数据执行此操作:

0 => "00101101"
1 => "00111000"
2 => "01001110"
3 => "01100010"

那么这些值“00101101”、“00111000”、“01001110”、“01100010”分别是 45、56、78 y 89 的二进制表示形式。 所以,你明白了......

有一个小细节,需要指定表示的位数: 如果你不这样做,你可以得到这个:

0 => "101101"
1 => "111000"
2 => "1001110"
3 => "1100010"

非常感谢所有可能的代码片段来完成这个程序

最佳答案

作为其他答案的替代方案,让您的 ROM 存储 naturalinteger(视情况而定)。那么你的常量可以是以下形式:

0 => 45,
1 => 56, ...

等等

如果您已经有了所有值,您可以将它们全部放在一个大逗号分隔符系列中,而无需进行 n => 位置映射。

(45, 56, 78, 98,....)

此外,如果您将地址输入为数字类型(unsignednatural,您可以根据自己的喜好),您可以简化地址解码

data <= my_rom(address);

data <= my_rom(to_integer(address));

关于Python:VHDL 代码生成器的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4967091/

相关文章:

logic - 4 位加减法逻辑

VHDL 中的 NULL 语句

vhdl - 赛灵思 "Dead code"

python - 哪一种效率更高?

python - 动态设置 tkinter Spinbox 的范围

java - JaxB - 如何不映射特定的 XML 节点

C#源文件合并

python - 如何从交互式 shell 访问调用源行

python - 跨网络的任务调度?

c++ - 如何自动生成C++函数?