【发布时间】:2017-02-19 22:24:49
【问题描述】:
我有一个 VHDL 代码。 Modelsim 给我报错
"预期长度为 32;实际长度为 31"
如何编写代码,它是正确的,我不写向量的长度。 我希望它像在 Verilog 中一样工作: Verilog
reg [30:0] smth1 = 2735*12;
reg [15:0] smth2 = 12*11;
reg [31:0] smth1_s;
always (*)
begin
smth1_s <= smth1+smth2;
end
VHDL:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity top is
end entity;
architecture top of top is
signal smth1 : unsigned(30 downto 0) := to_unsigned(2735,16) * to_unsigned(12,15); --reg [31:0] smth1 = 12'hAAF * 12;
signal smth2 : unsigned(15 downto 0) := to_unsigned(12,16) / to_unsigned(11,16); --reg [15:0] smth2 = 12*11;
signal smth1_s : unsigned(31 downto 0);
begin
smth1_s <= smth1 + smth2;
end architecture;
【问题讨论】:
-
"+"on Unsigned 接受输入并返回相同长度的输出。一种方法是对输入进行签名扩展:对于无符号,即smth1_s <= '0' & smth1 + '0' & smth2;