VHDL如何将std_逻辑向量与std_逻辑信号相加?
我有VHDL如何将std_逻辑向量与std_逻辑信号相加?,vhdl,Vhdl,我有 douta : in std_logic_vector (3 downto 0); doutb : in std_logic_vector (3 downto 0); c0 : in std_logic; f1 : in std_logic; f0 : in std_logic; res : out std_logic_vector (3 downto 0); 我正在尝试构建一个简单的ALU,这个ALU提供的功能之一是 什么时候 所以我写了
douta : in std_logic_vector (3 downto 0);
doutb : in std_logic_vector (3 downto 0);
c0 : in std_logic;
f1 : in std_logic;
f0 : in std_logic;
res : out std_logic_vector (3 downto 0);
我正在尝试构建一个简单的ALU,这个ALU提供的功能之一是
什么时候
所以我写了
f1 = '1' and f0 = '1' then res <= douta + doutb + c0;
你知道我如何解决这个问题吗
编辑:
也试过了
f1 = '1' and f0 = '1' then res <= douta + doutb + ("000" & c0);
您可以将c0转换为标准逻辑向量。我已经有很长时间没有用VHDL了
if f1 = '1' and f0 = '1' then
if c0 = '1' then
res <= douta + doutb + "0001";
else
res <= douta + doutb;
end if;
end if;
如果f1='1'和f0='1',则
如果c0='1',则
res哦,我想我找到了一个修复程序,需要添加以下库
use ieee.std_logic_arith.all;
我们尝试的方法会奏效:)多亏了@jdehaan,您不需要将std_逻辑转换为std_逻辑向量来进行加法。只需按原样进行加法,并确保“res”有足够的位来保存max答案。在这种情况下,res需要为5位宽,以便它现在溢出
作为一种风格,不要将输入端口命名为“dout”。那是糟糕的形式。在这里叫他们din,因为他们就是这样。在架构中,您可以将另一个名为“dout”的组件的输出端口连接到该组件的“din”上。如果要对其进行算术运算,请不要使用std\u logic\u vector
。使用ieee.numeric_std
,并使用有符号或无符号类型。然后,您可以将您的“0”或“1”添加到其中
使用std_logic_arith.all
的解决方法是使用非标准库,这会使您在更改工具链时陷入可移植性问题
我写了一个更详细的页面:
在comp.lang.vhdl上对此进行了一些讨论:在comp.lang.vhdl常见问题解答中也进行了讨论。感谢您的建议,是的,我尝试了f1='1'和f0='1',然后res如果要对它们进行算术,请不要使用std_逻辑向量。请参阅我的答案。+1链接到你的parallelpoints帖子。如果我在教学,我会让我所有的学生都必须阅读。谢谢@rick!我给一些刚开始使用FPGA的本科生做了一个讲座,并对此进行了一段时间的探讨:)
LHS=std_logic_vector!7, RHS=array_1_of_std_logic_3_d_0
if f1 = '1' and f0 = '1' then
if c0 = '1' then
res <= douta + doutb + "0001";
else
res <= douta + doutb;
end if;
end if;
if f1 = '1' and f0 = '1' then
if c0 = '1' then
res <= douta + doutb + "0001";
else
res <= douta + doutb + "0000";
end if;
end if;
use ieee.std_logic_arith.all;