1
我有一个VHDL代码。的ModelSim给我错误无符号VHDL
“长度的预期为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;
无符号的''+“'接受输入并返回相同长度的输出。一种方法是对输入进行符号扩展:对于无符号数,就是'smth1_s <='0'&smth1 +'0'&smth2;' –