Vhdl 在8位组件中测试24位信号

Vhdl 在8位组件中测试24位信号,vhdl,ghdl,Vhdl,Ghdl,我一直在做我的家庭作业,我们必须创建一个奇偶校验位发生器电路,对于一个8位序列,输出一个9位序列,其中新的是奇偶校验位(如果序列中有奇数个位为1,则设置为1)。这是它的代码: library ieee; use ieee.std_logic_1164.all; entity top is port( idata:in bit_vector(7 downto 0); odata:out bit_vector(8 downto 0)

我一直在做我的家庭作业,我们必须创建一个奇偶校验位发生器电路,对于一个8位序列,输出一个9位序列,其中新的是奇偶校验位(如果序列中有奇数个位为1,则设置为1)。这是它的代码:

library ieee;
use ieee.std_logic_1164.all;

entity top is
      port( 
            idata:in bit_vector(7 downto 0);
            odata:out bit_vector(8 downto 0)
            );
end top;

architecture parity_gen of top is
signal temp : bit_vector(5 downto 0);

begin
    temp(0)<=idata(0) xor idata(1);
    temp(1)<=temp(0) xor idata(2);
    temp(2)<=temp(1) xor idata(3);
    temp(3)<=temp(2) xor idata(4);
    temp(4)<=temp(3) xor idata(5);
    temp(5)<=temp(4) xor idata(6);
    odata(0)<= temp(5) xor idata(7);
    odata(1)<=idata(0);
    odata(2)<=idata(1);
    odata(3)<=idata(2);
    odata(4)<=idata(3);
    odata(5)<=idata(4);
    odata(6)<=idata(5);
    odata(7)<=idata(6);
    odata(8)<=idata(7);
end parity_gen;
我基本上想做这样的事情:

library ieee;
use ieee.std_logic_1164.all;

entity top_tb is end top_tb;

architecture behavior of top_tb is
    component top is
        port( 
            idata:in bit_vector(7 downto 0);
            odata:out bit_vector(8 downto 0)
            );
    end component;
    signal input  : bit_vector(7 downto 0);
    signal output : bit_vector(8 downto 0);
begin
    uut: top port map (
        idata(7 downto 0) => input(7 downto 0),
        odata(8 downto 0) => output(8 downto 0)
    );

    stim_proc: process
    begin
        input <= "10100101"; wait for 10 ns; assert output = "101001010" report "test failed";
        report "Top testbench finished";
        wait;
    end process;
end;
input <= "101001011100011110101100"; wait for 10 ns; assert output = "101001010110001111101011000" report "test failed";

input您可以创建一个forloop,在检查大小类似的输出数组时,只需迭代输入数组的元素

type t_in_array is array 0 to num_of_inputs of std_logic_vector(7 downto 0);
  signal s_input_arr : t_in_array := ("10100101", ...); 
type t_out_array is array 0 to num_of_inputs of std_logic_vector(8 downto 0);
  signal s_exp_out_arr: t_out_array := ("101001010", ...);

stim_proc: process
begin
for i in 0 to num_of_inputs
  input <= s_input_arr(i);
  wait for 10 ns;
  assert output = s_exp_out_arr(i)
    report "failed";
end loop;
wait;
end process stim_proc;
_数组中的类型t_是std_逻辑_向量的_输入的数组0到num_(7到0); 信号s_输入_arr:t_在_数组中:=((“10100101”,…); 类型t_out_array是标准逻辑向量的_输入的数组0到num_(8到0); 信号s_exp_out_arr:t_out_数组:=((“101001010”,…); 刺激程序:过程 开始 对于0中的i到输入的数量
输入您需要决定是否需要电路的多个实例,或者是否需要多路传输值。我只需要此电路的一个实例,因此我将多路传输值,并且我还考虑在此处添加一个输入时钟,以便它在上升沿上激活。但是我不知道怎么做……好吧,那是时候学习了我们不能从你身上卸下这个“包袱”。我并不是在找人帮我做这件事,只是想找一些关于去哪里找的建议,仅此而已。不过还是谢谢你,很好。StackOverflow上的推荐是离题的,但您可以通过最喜欢的web搜索引擎轻松找到关于各种VHDL内容的教程。
type t_in_array is array 0 to num_of_inputs of std_logic_vector(7 downto 0);
  signal s_input_arr : t_in_array := ("10100101", ...); 
type t_out_array is array 0 to num_of_inputs of std_logic_vector(8 downto 0);
  signal s_exp_out_arr: t_out_array := ("101001010", ...);

stim_proc: process
begin
for i in 0 to num_of_inputs
  input <= s_input_arr(i);
  wait for 10 ns;
  assert output = s_exp_out_arr(i)
    report "failed";
end loop;
wait;
end process stim_proc;