问题是我想使用这个sll
命令但是我得到了这个错误(在图片中)。我知道
bp := bp(0 to 6) & '0';
声明,但我还是想用这个。有人可以帮忙吗?
错误行: 从最后一个
开始library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std;
entity mul is
port(
a, b : in std_logic_vector(0 to 3);
c : out std_logic_vector(0 to 7));
end mul;
architecture mul of mul is
begin
process(a, b)
variable bp, p : std_logic_vector(0 to 7);
begin
bp := "0000"&b;
p := "00000000";
for k in 0 to 3 loop
if a(k) = '1' then
p := p + bp;
end if;
bp := bp sll 1;
end loop;
c <= p;
end process;
end mul;
答案 0 :(得分:1)
混合使用非标准VHDL(Synopsys)std_logic_unsigned
包和标准VHDL numeric_std
包可能会导致意外结果,因此我的建议是仅使用标准VHDL {{1} } package only only:
numeric_std
然后你可以这样做:
use ieee.numeric_std.all;
然后if a(k) = '1' then
p := std_logic_vector(unsigned(p) + unsigned(bp));
end if;
bp := std_logic_vector(unsigned(bp) sll 1);
包中的"sll"
函数用作中缀运算符,这与写入相同:
numeric_std
请注意,如果班次金额为1,则与写作相同:
bp := std_logic_vector("sll"(unsigned(bp), 1));
建议使用bp := std_logic_vector(shift_left(unsigned(bp), 1));
函数的最后一个语句,因为VHDL中的shift_left
运算符在VHDL-2008之前可能并不总是像预期的那样工作(阅读更多
GJS code),因此使用sll
包中的shift_left
函数可确保跨不同VHDL版本的可读性和预期操作。