在 VHDL 中设置可变长度 std_logic_vectors
Setting variable length std_logic_vectors in VHDL
我有一个 std_logic_vector、x: std_logice_vector(A+B-1 downto 0)
,我想将顶部 A
位设置为 '1'
,将底部 B
位设置为 '0'
, 有简单的方法吗?
我想做这样的事情:
x <= (A+B-1 downto B <= (others => '1'),
B-1 downto 0 <= (others => '0'));
我的其他计划是定义子信号并加入它们:
signal top: std_logic_vector(A-1 downto 0);
signal bottom: std_logic_vector(B-1 downto 0);
...
top <= (others => '0');
bottom <= (others => '1');
x <= top & bottom;
或者我可以编写一个循环遍历所有位的函数,但对于这么简单的事情来说,这似乎需要很多工作。
如果没有简单的方法,并且由于我需要多次执行此操作,我可能会定义一个常量并使用它。
另一种选择是使用别名。例如:
architecture test of foo is
signal x: std_logic_vector(A+B-1 downto 0);
alias x_upper is x(A+B-1 downto B);
alias x_lower is x(B-1 downto 0);
begin
x_upper <= (others => '1');
x_lower <= (others => '0');
end architecture test;
您可以像对待信号一样对待别名。 (而且它们是完全可合成的)。
我有一个 std_logic_vector、x: std_logice_vector(A+B-1 downto 0)
,我想将顶部 A
位设置为 '1'
,将底部 B
位设置为 '0'
, 有简单的方法吗?
我想做这样的事情:
x <= (A+B-1 downto B <= (others => '1'),
B-1 downto 0 <= (others => '0'));
我的其他计划是定义子信号并加入它们:
signal top: std_logic_vector(A-1 downto 0);
signal bottom: std_logic_vector(B-1 downto 0);
...
top <= (others => '0');
bottom <= (others => '1');
x <= top & bottom;
或者我可以编写一个循环遍历所有位的函数,但对于这么简单的事情来说,这似乎需要很多工作。
如果没有简单的方法,并且由于我需要多次执行此操作,我可能会定义一个常量并使用它。
另一种选择是使用别名。例如:
architecture test of foo is
signal x: std_logic_vector(A+B-1 downto 0);
alias x_upper is x(A+B-1 downto B);
alias x_lower is x(B-1 downto 0);
begin
x_upper <= (others => '1');
x_lower <= (others => '0');
end architecture test;
您可以像对待信号一样对待别名。 (而且它们是完全可合成的)。