用前导零填充std_logic_vector

Jam*_*es0 10 vhdl

好吧,我想做的是将一个较小的std_vector分配给一个较大的std_vector,用零填充高位.但是,我想要一些通用且简单的东西,而不需要知道每个第一个的大小.

例如,如果我有:

signal smaller_vec: std_logic_vector(15 downto 0);
signal larger_vec: std_logic_vector(31 downto 0);
Run Code Online (Sandbox Code Playgroud)

我可以:

larger_vec <= X"0000" & smaller_vec;
Run Code Online (Sandbox Code Playgroud)

但是,如果我不知道较小的矢量的大小,该怎么办?是否指定所有高位都为零.

我知道其他条款,但由于我需要几行,这会变得混乱:

larger_vec(smaller_vec'high downto 0) <= smaller_vec;
larger_vec(31 downto smaller_vec'length) <= (others => '0');
Run Code Online (Sandbox Code Playgroud)

我以为我可以用:

larger_vec <= "" & smaller_vec;
Run Code Online (Sandbox Code Playgroud)

但这没用.有任何想法吗?

Jim*_*wis 8

你有没有尝试过:

larger_vec <= (31 downto smaller_vec'length => '0') & smaller_vec;
Run Code Online (Sandbox Code Playgroud)

在过去,我有像这样的代码的综合工具问题,所以我用过:

constant ZERO : std_logic_vector(larger_vec'range) := (others => '0');
. . .
larger_vec <= ZERO(31 downto smaller_vec'length) & smaller_vec;
Run Code Online (Sandbox Code Playgroud)

  • 你也可以做`greater_vec <=(greater_vec'left downto smaller_vec'length =>'0')&smaller_vec;`因此你甚至不必指定`31`. (2认同)

Jam*_*es0 2

就我而言,我还喜欢以下内容:

larger_vec <= (smaller_vec'high downto 0 <= smaller_vec, others => '0');
Run Code Online (Sandbox Code Playgroud)

这就是我最后的答案。这有效,是吗?