Vhdl 如何检查在使用运算符重载添加std_逻辑_向量时生成的任何进位?

Vhdl 如何检查在使用运算符重载添加std_逻辑_向量时生成的任何进位?,vhdl,Vhdl,我尝试使用下面给出的符号添加两个std_逻辑_向量:- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; --use IEEE.NUMERIC_STD.ALL; entity adder is port( a:in std_logic_vector(31 downto 0); b:in std_logic_vector(31

我尝试使用下面给出的符号添加两个std_逻辑_向量:-

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--use IEEE.NUMERIC_STD.ALL;

entity adder is
port( a:in std_logic_vector(31 downto 0);
    b:in std_logic_vector(31 downto 0);
    o:out std_logic_vector(31 downto 0));
end adder;

architecture Behavioral of adder is

begin
o<=a+b;

end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.STD_LOGIC_ARITH.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
--使用IEEE.NUMERIC_STD.ALL;
实体加法器是
端口(a:std_逻辑_向量中(31向下至0);
b:标准逻辑向量(31到0);
o:输出标准逻辑向量(31到0);
末端加法器;
介绍了加法器的结构
开始

o一种可能性是使用进位生成结果,然后拆分,如:

architecture Behavioral of adder is
    signal c_o : std_logic_vector(o'length downto 0);  -- Result with carry
    signal c   : std_logic;  -- Carry only
begin
    c_o <= ('0' & a) + b;  -- Result with carry; extended with '0' to keep carry 
    o <= c_o(o'range);     -- Result without carry
    c <= c_o(c_o'left);    -- Carry only
end Behavioral;
加法器的结构是 信号c_o:std_逻辑_向量(o'长度下降到0);--带进位的结果 信号c:std_逻辑;——仅携带 开始
你可以这样做。进货未保存,但据报告有溢出

function "+" (Add1: std_logic_vector; Add2: std_logic_vector) return std_logic_vector is
    variable big_sum: bit_vector(Add1'LENGTH downto 0);
begin
    big_sum = Add1 + Add2;
    assert big_sum(Add1'LENGTH) = 0
      report "overflow"
      severity warning;
    return big_sum(Add1'LENGTH-1 downto 0);

当然,您需要定义一个新的包,并将该包包含在您现有的文件中。

o您希望如何记录该携带?您想要一个警告还是希望它保存在某个地方?另外,您是否特别希望运算符重载?是的,我想保存它。但这已经被@Morten Zilmer回答了。谢谢…..我想OP需要一个加号运算符。在基于原始长度进行加法时,carry会自动丢失,因为结果将有长度的参数,因此没有任何进位空间。我尝试在代码中使用unsigned,但“unsigned”的颜色不会改变,我尝试使用numeric_std。也没有任何结果。如果unsigned的颜色没有改变,则表示它不是关键字。在上述注释的继续部分:-那么我应该如何定义unsigned端口或信号?unsigned是ieee.numeric_std中的关键字。unsigned也在std_LOGIC_ARITH中定义。您应该使用ieee.numeric\u std over std\u logic\u aritun指定端口的声明方式与std\u logic\u vector完全相同只需将std\u logic\u vector替换为unsigned
o<=std_logic_vector(unsigned(a)+unsigned(b))
o_with_carry <= std_logic_vector('0'&unsigned(a)+unsigned(b));
o_carry <= o_with_carry(o_with_carry'high);
o <=  o_with_carry(o'range);