标量与向量的乘法

时间:2012-11-10 05:45:52

标签: vhdl

我在VHDL中编写代码,其中数字乘以向量。但它给出了一个错误。

Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity multi is
 port (    clk   :  in std_logic;
          ipixel :  in std_logic_vector(15 downto 0);
          opixel  :  out std_logic_vector(15 downto 0)
      );

end entity multi;

architecture rtl of multi is
begin

process (clk) begin
  if rising_edge (clk) then

        opixel (15 downto 11) <=  std_logic_vector(unsigned(ipixel(15 downto 11))*3);
        opixel (10 downto 5)  <= std_logic_vector(unsigned(ipixel(10 downto 5))* 3);
        opixel (4 downto 0)   <= std_logic_vector(unsigned(ipixel(4 downto 0))* 3);

    end if;
end process;
end architecture rtl;

错误是:

  

目标切片5个元素;价值是10个元素

1 个答案:

答案 0 :(得分:3)

当您将无符号值自然相乘时,会在NUMERIC_STD中定义,如下所示:

function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
begin
    return L * TO_UNSIGNED(R, L'LENGTH);
end "*";

返回值将导致您的无符号系数的2 * length