【发布时间】:2015-01-22 06:27:37
【问题描述】:
对于定点算术,我用 0000 0010101010100110 表示 0.166 并将其乘以相同的值。为此,我用 VHDL 编写了如下代码。输出分配在 y 中,它有符号 41 位。对于有符号乘法 A(a1,b1)*A(a2,b2)=A(a1+a2+1,b1+b2)。然而在模拟过程中它给出了一个错误
Target Size 41 and source size 40 for array dimension 0 does not match.
代码:
entity file1 is
Port ( y : out signed(40 downto 0));
end file1;
architecture Behavioral of file1 is
signal a : signed(19 downto 0) := "00000010101010100110";
signal b : signed(19 downto 0) := "00000010101010100110";
begin
y<= (a*b); ----error
end Behavioral;
【问题讨论】:
-
dk14 的回答详细说明了为什么长度是这样的,这是值得的,但可能更容易记住,通常,乘法的结果长度只是操作数长度的总和,对于
signed和unsigned。 20 位 * 20 位 = 40 位。 -
如果你真的想要定点,为什么不使用IEEE定点包中的sfixed(VHDL-2008添加)?
标签: vhdl multiplication hdl fixed-point